Skip to content

Union[X, NoReturn] isn't properly narrowed to X #11876

Closed
@tusharsadhwani

Description

@tusharsadhwani
from typing import Union, NoReturn

def func() -> Union[str, NoReturn]:
    return 'test'

func().lower()

Here, Unoin[str, NoReturn] should effectively be treated as the same as str. But mypy doesn't seem to do that.

$ mypy code.py
code.py:6: error: Item "NoReturn" of "Union[str, NoReturn]" has no attribute "lower"
Found 1 error in 1 file (checked 1 source file)

More information in this discussion page: python/typing#994 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions