Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b279f4c

Browse files
authored
Don't do any tricky inference in deferred nodes (#7134)
Fixes #7126
1 parent d8cde02 commit b279f4c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

mypy/checker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,9 @@ def check_multi_assignment_from_tuple(self, lvalues: List[Lvalue], rvalue: Expre
24102410
reinferred_rvalue_type, context,
24112411
infer_lvalue_type)
24122412
return
2413+
if isinstance(reinferred_rvalue_type, AnyType) and self.current_node_deferred:
2414+
# Doing more inference in deferred nodes can be hard, so give up for now.
2415+
return
24132416
assert isinstance(reinferred_rvalue_type, TupleType)
24142417
rvalue_type = reinferred_rvalue_type
24152418

test-data/unit/check-inference.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,3 +2749,15 @@ def g() -> None:
27492749
x + 'no way' # E: Unsupported operand types for + ("int" and "str")
27502750
x = int()
27512751
f()
2752+
2753+
[case testDeferralOfMemberNested]
2754+
from typing import Tuple
2755+
2756+
def f() -> None:
2757+
c: C
2758+
t: Tuple[str, Tuple[str, str]]
2759+
x, (y, c.a) = t # E: Incompatible types in assignment (expression has type "str", variable has type "int")
2760+
2761+
class C:
2762+
def __init__(self, a: int) -> None:
2763+
self.a = a

0 commit comments

Comments
 (0)