Skip to content

Commit 72349c0

Browse files
committed
Non-ambiguous Never is fine as inference result
1 parent 475f8b1 commit 72349c0

File tree

6 files changed

+4
-18
lines changed

6 files changed

+4
-18
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8500,7 +8500,7 @@ def is_valid_inferred_type(typ: Type, is_lvalue_final: bool = False) -> bool:
85008500
# the context. This resolution happens in leave_partial_types when
85018501
# we pop a partial types scope.
85028502
return is_lvalue_final
8503-
elif isinstance(proper_type, UninhabitedType):
8503+
elif isinstance(proper_type, UninhabitedType) and proper_type.ambiguous:
85048504
return False
85058505
return not typ.accept(InvalidInferredTypes())
85068506

test-data/unit/check-incremental.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5415,8 +5415,6 @@ reveal_type(z)
54155415
[out]
54165416
tmp/c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">"
54175417
[out2]
5418-
tmp/a.py:7: error: Need type annotation for "y"
5419-
tmp/b.py:2: error: Need type annotation for "z"
54205418
tmp/c.py:2: note: Revealed type is "Never"
54215419

54225420
[case testIsInstanceAdHocIntersectionIncrementalUnreachableToIntersection]
@@ -5448,8 +5446,6 @@ from b import z
54485446
reveal_type(z)
54495447
[builtins fixtures/isinstance.pyi]
54505448
[out]
5451-
tmp/a.py:7: error: Need type annotation for "y"
5452-
tmp/b.py:2: error: Need type annotation for "z"
54535449
tmp/c.py:2: note: Revealed type is "Never"
54545450
[out2]
54555451
tmp/c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">"

test-data/unit/check-python38.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def f1() -> None:
697697
x = 1
698698

699699
if (x := d[x]) is None: # E: Name "x" may be undefined
700-
y = x # E: Need type annotation for "y"
700+
y = x
701701
z = x
702702
[builtins fixtures/dict.pyi]
703703

test-data/unit/check-tuples.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ for x in t:
940940
[case testForLoopOverEmptyTuple]
941941
import typing
942942
t = ()
943-
for x in t: pass # E: Need type annotation for "x"
943+
for x in t: pass
944944
[builtins fixtures/for.pyi]
945945

946946
[case testForLoopOverNoneValuedTuple]
@@ -1604,7 +1604,6 @@ t5: Tuple[int, int] = (1, 2, "s", 4) # E: Incompatible types in assignment (exp
16041604

16051605
# long initializer assignment with mismatched pairs
16061606
t6: Tuple[int, int, int, int, int, int, int, int, int, int, int, int] = (1, 2, 3, 4, 5, 6, 7, 8, "str", "str", "str", "str", 1, 1, 1, 1, 1) # E: Incompatible types in assignment (expression has type Tuple[int, int, ... <15 more items>], variable has type Tuple[int, int, ... <10 more items>])
1607-
16081607
[builtins fixtures/tuple.pyi]
16091608

16101609
[case testTupleWithStarExpr]

test-data/unit/check-unreachable-code.test

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,12 +1550,7 @@ x = 0 # not unreachable
15501550
[case testUnpackNever]
15511551
x: str
15521552
if isinstance(x, int):
1553-
# mypy wants a type annotation for y because it's `Never`.
1554-
# This doesn't make much sense in this case, but it's a
1555-
# requirement for composable behavior.
1556-
# (and `ys` should also get flagged.)
1557-
1558-
y, *ys = x # E: Need type annotation for "y"
1553+
y, *ys = x
15591554
reveal_type(y) # N: Revealed type is "Never"
15601555
reveal_type(ys) # N: Revealed type is "builtins.list[Never]"
15611556
[builtins fixtures/isinstancelist.pyi]

test-data/unit/fine-grained.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9693,8 +9693,6 @@ reveal_type(z)
96939693
c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">"
96949694
==
96959695
c.py:2: note: Revealed type is "Never"
9696-
a.py:7: error: Need type annotation for "y"
9697-
b.py:2: error: Need type annotation for "z"
96989696

96999697
[case testIsInstanceAdHocIntersectionFineGrainedIncrementalUnreachableToIntersection]
97009698
import c
@@ -9725,8 +9723,6 @@ from b import z
97259723
reveal_type(z)
97269724
[builtins fixtures/isinstance.pyi]
97279725
[out]
9728-
a.py:7: error: Need type annotation for "y"
9729-
b.py:2: error: Need type annotation for "z"
97309726
c.py:2: note: Revealed type is "Never"
97319727
==
97329728
c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">"

0 commit comments

Comments
 (0)