@@ -2716,23 +2716,81 @@ if type(x) == type(y) == int:
27162716 reveal_type(y) # N: Revealed type is "builtins.int"
27172717 reveal_type(x) # N: Revealed type is "builtins.int"
27182718
2719+ z: Any
2720+ if int == type(z) == int:
2721+ reveal_type(z) # N: Revealed type is "builtins.int"
2722+
27192723[case testTypeEqualsCheckUsingIs]
27202724from typing import Any
27212725
27222726y: Any
27232727if type(y) is int:
27242728 reveal_type(y) # N: Revealed type is "builtins.int"
27252729
2730+ [case testTypeEqualsCheckUsingImplicitTypes]
2731+ from typing import Any
2732+
2733+ x: str
2734+ y: Any
2735+ z: object
2736+ if type(y) is type(x):
2737+ reveal_type(x) # N: Revealed type is "builtins.str"
2738+ reveal_type(y) # N: Revealed type is "builtins.str"
2739+
2740+ if type(x) is type(z):
2741+ reveal_type(x) # N: Revealed type is "builtins.str"
2742+ reveal_type(z) # N: Revealed type is "builtins.str"
2743+
2744+ [case testTypeEqualsCheckUsingDifferentSpecializedTypes]
2745+ from collections import defaultdict
2746+
2747+ x: defaultdict
2748+ y: dict
2749+ z: object
2750+ if type(x) is type(y) is type(z):
2751+ reveal_type(x) # N: Revealed type is "collections.defaultdict[Any, Any]"
2752+ reveal_type(y) # N: Revealed type is "collections.defaultdict[Any, Any]"
2753+ reveal_type(z) # N: Revealed type is "collections.defaultdict[Any, Any]"
2754+
2755+ [case testUnionTypeEquality]
2756+ from typing import Any, reveal_type
2757+ # flags: --warn-unreachable
2758+
2759+ x: Any = ()
2760+ if type(x) == (int, str):
2761+ reveal_type(x) # E: Statement is unreachable
2762+
2763+ [builtins fixtures/tuple.pyi]
2764+
2765+ [case testTypeIntersectionWithConcreteTypes]
2766+ class X: x = 1
2767+ class Y: y = 1
2768+ class Z(X, Y): ...
2769+
2770+ z = Z()
2771+ x: X = z
2772+ y: Y = z
2773+ if type(x) is type(y):
2774+ reveal_type(x) # N: Revealed type is "__main__.<subclass of "__main__.X" and "__main__.Y">"
2775+ reveal_type(y) # N: Revealed type is "__main__.<subclass of "__main__.Y" and "__main__.X">"
2776+ x.y + y.x
2777+
2778+ if isinstance(x, type(y)) and isinstance(y, type(x)):
2779+ reveal_type(x) # N: Revealed type is "__main__.<subclass of "__main__.X" and "__main__.Y">"
2780+ reveal_type(y) # N: Revealed type is "__main__.<subclass of "__main__.X" and "__main__.Y">"
2781+ x.y + y.x
2782+
2783+ [builtins fixtures/isinstance.pyi]
2784+
27262785[case testTypeEqualsCheckUsingIsNonOverlapping]
27272786# flags: --warn-unreachable
27282787from typing import Union
27292788
27302789y: str
2731- if type(y) is int: # E: Subclass of "str" and "int" cannot exist: would have incompatible method signatures
2732- y # E: Statement is unreachable
2790+ if type(y) is int:
2791+ y
27332792else:
27342793 reveal_type(y) # N: Revealed type is "builtins.str"
2735- [builtins fixtures/isinstance.pyi]
27362794
27372795[case testTypeEqualsCheckUsingIsNonOverlappingChild-xfail]
27382796# flags: --warn-unreachable
@@ -2762,12 +2820,13 @@ else:
27622820[case testTypeEqualsMultipleTypesShouldntNarrow]
27632821# flags: --warn-unreachable
27642822# make sure we don't do any narrowing if there are multiple types being compared
2823+ # flags: --warn-unreachable
27652824
27662825from typing import Union
27672826
27682827x: Union[int, str]
27692828if type(x) == int == str:
2770- reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
2829+ reveal_type(x) # E: Statement is unreachable
27712830else:
27722831 reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
27732832
0 commit comments