Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tusharsadhwani opened this issue Dec 30, 2021 · 2 comments
Closed

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

tusharsadhwani opened this issue Dec 30, 2021 · 2 comments
Labels
bug mypy got something wrong

Comments

@tusharsadhwani
Copy link
Contributor

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)

@tusharsadhwani tusharsadhwani added the bug mypy got something wrong label Dec 30, 2021
@gschaffner
Copy link
Contributor

This appears to be fixed as of Mypy 0.940.

@hauntsaninja
Copy link
Collaborator

Thanks, this was fixed in #11996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants