Skip to content

Commit 4718cfd

Browse files
committed
Update some tests
1 parent be6573e commit 4718cfd

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

mypy/binder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ def put(self, expr: Expression, typ: Type, *, from_assignment: bool = True) -> N
168168
169169
This is used for isinstance() etc. Assignments should go through assign_type().
170170
"""
171-
if isinstance(get_proper_type(typ), UninhabitedType):
171+
proper_typ = get_proper_type(typ)
172+
if isinstance(proper_typ, UninhabitedType) and not proper_typ.ambiguous:
172173
self.frames[-1].unreachable = True
173174

174175
if not isinstance(expr, (IndexExpr, MemberExpr, NameExpr)):

test-data/unit/check-narrowing.test

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ else:
263263
reveal_type(x) # N: Revealed type is "Union[__main__.Object1, __main__.Object2]"
264264

265265
if x.key is Key.D:
266-
# TODO: this should narrow to Never
267266
reveal_type(x) # E: Statement is unreachable \
268267
# N: Revealed type is "Never"
269268
else:
@@ -2448,13 +2447,19 @@ def foo(x: T) -> T:
24482447

24492448
[case testNarrowingToClassWithNeverProperty]
24502449
# flags: --warn-unreachable
2451-
from typing import Never
2450+
from typing import Never, Union
24522451

24532452
class X:
24542453
a: Never
24552454

2456-
x: X
2457-
if x.a is 5:
2458-
reveal_type(x) # N: Revealed type is "__main__.X"
2455+
class B:
2456+
a: str
2457+
2458+
x: Union[X, B]
2459+
# TODO: this should not be unreachable (`Never & int` is just `Never`)
2460+
if isinstance(x.a, int): # E: Subclass of "str" and "int" cannot exist: would have incompatible method signatures
2461+
reveal_type(x) # E: Statement is unreachable \
2462+
# N: Revealed type is "__main__.X"
24592463
else:
2460-
reveal_type(x) # N: Revealed type is "__main__.X"
2464+
reveal_type(x) # N: Revealed type is "Union[__main__.X, __main__.B]"
2465+
[builtins fixtures/isinstancelist.pyi]

test-data/unit/deps.test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,7 @@ class B:
414414

415415
def f(x: A) -> None:
416416
if isinstance(x, B):
417-
# TODO: this should narrow to Never and therefore not error
418-
#x.y
419-
pass
417+
x.y
420418
[builtins fixtures/isinstancelist.pyi]
421419
[out]
422420
<m.A> -> <m.f>, m.A, m.f

0 commit comments

Comments
 (0)