Skip to content
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

unreachable code isn't type checked #11649

Closed
DetachHead opened this issue Dec 1, 2021 · 2 comments
Closed

unreachable code isn't type checked #11649

DetachHead opened this issue Dec 1, 2021 · 2 comments
Labels
bug mypy got something wrong

Comments

@DetachHead
Copy link
Contributor

foo: str

if isinstance(foo, str):
    ...
else:
    asdf: list[str] = "" # no error

https://mypy-play.net/?mypy=master&python=3.10&gist=98cc704dbc9936fa1c3801984cd631fd

my use case is an assert_unreachable function:

def assert_unreachable(msg: str):
    raise AssertionError(msg)

foo: str

if isinstance(foo, str):
    ...
else:
    # no error even though the msg argument was not provided
    assert_unreachable() #type:ignore[unreachable]
@hauntsaninja
Copy link
Collaborator

Yeah, this is intentional. https://mypy.readthedocs.io/en/stable/common_issues.html#unreachable-code
I think in practice basically all warnings mypy would give if it didn't do this would end up being false positives.

@KotlinIsland
Copy link
Contributor

@hauntsaninja Those docs don't really explain why "this would end up being false positives", only showing very obvious true positives being ignored.

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