@@ -734,11 +734,9 @@ while bool():
734734 x + 1
735735 break
736736 # TODO: only report unreachability once
737- # TODO: narrow x to Never
738- elif isinstance(x, str): # E: Statement is unreachable \
739- # E: Subclass of "int" and "str" cannot exist: would have incompatible method signatures
737+ elif isinstance(x, str): # E: Statement is unreachable
740738 _ = "unreachable" # E: Statement is unreachable
741- x + 'a' # E: Unsupported operand types for + ("int" and "str ")
739+ x + 'a' # E: Unsupported left operand type for + ("Never ")
742740 break
743741 _ = "unreachable" # E: Statement is unreachable
744742x + [1] # E: Unsupported operand types for + ("int" and "List[int]") \
@@ -1275,7 +1273,8 @@ if isinstance(y, int) and isinstance(x, B): # E: Subclass of "A" and "int" cann
12751273 # E: Right operand of "and" is never evaluated
12761274 _ = "unreachable" # E: Statement is unreachable
12771275if isinstance(y, int) and y > 42: # E: Subclass of "A" and "int" cannot exist: would have incompatible method signatures \
1278- # E: Right operand of "and" is never evaluated
1276+ # E: Right operand of "and" is never evaluated \
1277+ # E: Unsupported left operand type for > ("Never")
12791278 _ = "unreachable" # E: Statement is unreachable
12801279[builtins fixtures/isinstancelist.pyi]
12811280
@@ -1370,9 +1369,9 @@ x = B()
13701369if isinstance(x, A):
13711370 reveal_type(x) # N: Revealed type is "__main__.B"
13721371if not isinstance(x, A):
1373- reveal_type(x) # E: Statement is unreachable \
1374- # N: Revealed type is "__main__.B"
1375- x = A() # E: Incompatible types in assignment (expression has type "A", variable has type "B")
1372+ reveal_type(x) # N: Revealed type is "Never"
1373+ x = A() # E: Statement is unreachable \
1374+ # E: Incompatible types in assignment (expression has type "A", variable has type "B")
13761375reveal_type(x) # N: Revealed type is "__main__.B"
13771376[builtins fixtures/isinstance.pyi]
13781377
@@ -1537,8 +1536,7 @@ from typing import Type, Sequence, Union
15371536
15381537x: Type[str]
15391538if issubclass(x, int): # E: Subclass of "str" and "int" cannot exist: would have incompatible method signatures
1540- reveal_type(x) # E: Statement is unreachable \
1541- # N: Revealed type is "Type[builtins.str]"
1539+ reveal_type(x) # N: Revealed type is "Type[builtins.str]"
15421540
15431541class X: pass
15441542class Y(X): pass
@@ -1548,8 +1546,7 @@ a: Union[Type[Y], Type[Z]]
15481546if issubclass(a, X):
15491547 reveal_type(a) # N: Revealed type is "Union[Type[__main__.Y], Type[__main__.Z]]"
15501548else:
1551- reveal_type(a) # E: Statement is unreachable \
1552- # N: Revealed type is "Union[Type[__main__.Y], Type[__main__.Z]]"
1549+ reveal_type(a) # N: Revealed type is "Union[Type[__main__.Y], Type[__main__.Z]]"
15531550[builtins fixtures/isinstancelist.pyi]
15541551
15551552[case testIssubclasDestructuringUnions1]
@@ -1891,8 +1888,7 @@ def f(x: Type[int]) -> None:
18911888 if isinstance(x, type):
18921889 reveal_type(x) # N: Revealed type is "Type[builtins.int]"
18931890 else:
1894- reveal_type(x) # E: Statement is unreachable \
1895- # N: Revealed type is "Type[builtins.int]"
1891+ reveal_type(x) # N: Revealed type is "Never"
18961892 reveal_type(x) # N: Revealed type is "Type[builtins.int]"
18971893[builtins fixtures/isinstance.pyi]
18981894
@@ -2392,17 +2388,15 @@ class C:
23922388class Example(A, B): pass # E: Definition of "f" in base class "A" is incompatible with definition in base class "B"
23932389x: A
23942390if isinstance(x, B): # E: Subclass of "A" and "B" cannot exist: would have incompatible method signatures
2395- reveal_type(x) # E: Statement is unreachable \
2396- # N: Revealed type is "__main__.A"
2391+ reveal_type(x) # N: Revealed type is "Never"
23972392else:
23982393 reveal_type(x) # N: Revealed type is "__main__.A"
23992394
24002395y: C
24012396if isinstance(y, B):
24022397 reveal_type(y) # N: Revealed type is "__main__.<subclass of "__main__.C" and "__main__.B">"
24032398 if isinstance(y, A): # E: Subclass of "C", "B", and "A" cannot exist: would have incompatible method signatures
2404- reveal_type(y) # E: Statement is unreachable \
2405- # N: Revealed type is "__main__.<subclass of "__main__.C" and "__main__.B">"
2399+ reveal_type(y) # N: Revealed type is "Never"
24062400[builtins fixtures/isinstance.pyi]
24072401
24082402[case testIsInstanceAdHocIntersectionReversed]
@@ -2431,7 +2425,7 @@ class B:
24312425 def t0(self) -> None:
24322426 if isinstance(self, A0): # E: Subclass of "B" and "A0" cannot exist: would have incompatible method signatures
24332427 x0: Literal[0] = self.f() # E: Statement is unreachable \
2434- # E: Incompatible types in assignment (expression has type "Literal[1, 2]", variable has type "Literal[0]")
2428+ # E: "Never" has no attribute "f"
24352429
24362430 def t1(self) -> None:
24372431 if isinstance(self, A1):
@@ -2468,8 +2462,7 @@ class B:
24682462
24692463x: A[int]
24702464if isinstance(x, B): # E: Subclass of "A[int]" and "B" cannot exist: would have incompatible method signatures
2471- reveal_type(x) # E: Statement is unreachable \
2472- # N: Revealed type is "__main__.A[builtins.int]"
2465+ reveal_type(x) # N: Revealed type is "Never"
24732466else:
24742467 reveal_type(x) # N: Revealed type is "__main__.A[builtins.int]"
24752468
@@ -2509,29 +2502,28 @@ def f1(x: T1) -> T1:
25092502 # N: Revealed type is "__main__.<subclass of "__main__.B" and "__main__.A">"
25102503 else:
25112504 reveal_type(x) # N: Revealed type is "__main__.A" \
2512- # N: Revealed type is "__main__.<subclass of "__main__.B" and "__main__.A"> "
2505+ # N: Revealed type is "Never "
25132506 else:
2514- reveal_type(x) # N: Revealed type is "__main__.A " \
2507+ reveal_type(x) # N: Revealed type is "Never " \
25152508 # N: Revealed type is "__main__.B"
25162509 return x
25172510
25182511T2 = TypeVar('T2', B, C)
25192512def f2(x: T2) -> T2:
25202513 if isinstance(x, B):
25212514 reveal_type(x) # N: Revealed type is "__main__.B" \
2522- # N: Revealed type is "__main__.C "
2515+ # N: Revealed type is "Never "
25232516 # Note: even though --warn-unreachable is set, we don't report
25242517 # errors for the below: we don't yet have a way of filtering out
25252518 # reachability errors that occur for only one variation of the
25262519 # TypeVar yet.
25272520 if isinstance(x, C):
2528- reveal_type(x) # N: Revealed type is "__main__.B" \
2529- # N: Revealed type is "__main__.C"
2521+ reveal_type(x) # N: Revealed type is "Never"
25302522 else:
25312523 reveal_type(x) # N: Revealed type is "__main__.B" \
2532- # N: Revealed type is "__main__.C "
2524+ # N: Revealed type is "Never "
25332525 else:
2534- reveal_type(x) # N: Revealed type is "__main__.B " \
2526+ reveal_type(x) # N: Revealed type is "Never " \
25352527 # N: Revealed type is "__main__.C"
25362528 return x
25372529
@@ -2648,8 +2640,7 @@ class B(Y, X): pass
26482640
26492641foo: A
26502642if isinstance(foo, B): # E: Subclass of "A" and "B" cannot exist: would have inconsistent method resolution order
2651- reveal_type(foo) # E: Statement is unreachable \
2652- # N: Revealed type is "__main__.A"
2643+ reveal_type(foo) # N: Revealed type is "Never"
26532644[builtins fixtures/isinstance.pyi]
26542645
26552646[case testIsInstanceAdHocIntersectionAmbiguousClass]
@@ -2683,8 +2674,7 @@ x: Type[A]
26832674if issubclass(x, B):
26842675 reveal_type(x) # N: Revealed type is "Type[__main__.<subclass of "__main__.A" and "__main__.B">]"
26852676 if issubclass(x, C): # E: Subclass of "A", "B", and "C" cannot exist: would have incompatible method signatures
2686- reveal_type(x) # E: Statement is unreachable \
2687- # N: Revealed type is "Type[__main__.<subclass of "__main__.A" and "__main__.B">]"
2677+ reveal_type(x) # N: Revealed type is "Type[__main__.<subclass of "__main__.A" and "__main__.B">]"
26882678 else:
26892679 reveal_type(x) # N: Revealed type is "Type[__main__.<subclass of "__main__.A" and "__main__.B">]"
26902680else:
0 commit comments