8000 Retain None (unreachable) when typemap is None with `type(x) is Foo` check by sterliakov · Pull Request #18486 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Retain None (unreachable) when typemap is None with type(x) is Foo check #18486

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add more explicit tests
  • Loading branch information
sterliakov committed Jan 18, 2025
commit 0d549ad13089d87b684fb35fcae5a3add621481c
27 changes: 27 additions & 0 deletions test-data/unit/check-isinstance.test
Original file line number Diff line number Diff line change
Expand Up @@ -2661,6 +2661,33 @@ y: Any
if type(y) is int:
reveal_type(y) # N: Revealed type is "builtins.int"

[case testTypeEqualsCheckUsingIsNonOverlapping]
# flags: --warn-unreachable
from typing import Union

y: str
if type(y) is int: # E: Subclass of "str" and "int" cannot exist: would have incompatible method signatures
y # E: Statement is unreachable
else:
reveal_type(y) # N: Revealed type is "builtins.str"
[builtins fixtures/isinstance.pyi]

[case testTypeEqualsCheckUsingIsNonOverlappingChild-xfail]
# flags: --warn-unreachable
from typing import Union

class A: ...
class B: ...
class C(A): ...
x: Union[B, C]
# C instance cannot be exactly its parent A, we need reversed subtyping relationship
# here (type(parent) is Child).
if type(x) is A:
reveal_type(x) # E: Statement is unreachable
else:
reveal_type(x) # N: Revealed type is "Union[__main__.B, __main__.C]"
[builtins fixtures/isinstance.pyi]

[case testTypeEqualsNarrowingUnionWithElse]
from typing import Union

Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-typevar-values.test
Original file line number Diff line number Diff line change
Expand Up @@ -744,5 +744,4 @@ def fn(w: W) -> W:
elif type(w) is int:
reveal_type(w) # N: Revealed type is "builtins.int"
return w

[builtins fixtures/isinstance.pyi]
Loading
0