Skip to content

Commit a9d61fa

Browse files
committed
Avoid another crash in partial type inference. Fix #1269. (#1445)
1 parent 8a4d694 commit a9d61fa

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ def check_indexed_assignment(self, lvalue: IndexExpr,
15281528
def try_infer_partial_type_from_indexed_assignment(
15291529
self, lvalue: IndexExpr, rvalue: Node) -> None:
15301530
# TODO: Should we share some of this with try_infer_partial_type?
1531-
if isinstance(lvalue.base, RefExpr):
1531+
if isinstance(lvalue.base, RefExpr) and isinstance(lvalue.base.node, Var):
15321532
var = cast(Var, lvalue.base.node)
15331533
if var is not None and isinstance(var.type, PartialType):
15341534
type_type = var.type.type

mypy/test/data/check-inference.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,3 +1696,12 @@ def f(): pass
16961696
a = {0: [0]} if f() else {0: []}
16971697
a() # E: Dict[int, List[int]] not callable
16981698
[builtins fixtures/dict.py]
1699+
1700+
[case testMisguidedSetItem]
1701+
from typing import Generic, Sequence, TypeVar
1702+
T = TypeVar('T')
1703+
class C(Sequence[T], Generic[T]): pass
1704+
C[0] = 0
1705+
[out]
1706+
main:4: error: Type expected within [...]
1707+
main:4: error: Unsupported target for indexed assignment

0 commit comments

Comments
 (0)