Skip to content

Commit 25b614c

Browse files
Guido van RossumJukkaL
Guido van Rossum
authored andcommitted
Fix #1082 -- internal error when updating partial type from outer scope.
1 parent 2a19956 commit 25b614c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mypy/checkexpr.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ def analyze_ref_expr(self, e: RefExpr) -> Type:
7575
result = self.analyze_var_ref(node, e)
7676
if isinstance(result, PartialType):
7777
partial_types = self.chk.partial_types[-1]
78-
context = partial_types[node]
79-
self.msg.fail(messages.NEED_ANNOTATION_FOR_VAR, context)
78+
if node in partial_types:
79+
context = partial_types[node]
80+
self.msg.fail(messages.NEED_ANNOTATION_FOR_VAR, context)
8081
result = AnyType()
8182
elif isinstance(node, FuncDef):
8283
# Reference to a global function.

mypy/test/data/check-inference.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,13 @@ b[{}] = 1
11911191
[builtins fixtures/dict.py]
11921192
[out]
11931193

1194+
[case testInferDictInitializedToEmptyAndUpdatedFromMethod]
1195+
map = {} # E: Need type annotation for variable
1196+
def add():
1197+
map[1] = 2
1198+
[builtins fixtures/dict.py]
1199+
[out]
1200+
11941201
[case testSpecialCaseEmptyListInitialization]
11951202
def f(blocks: Any): # E: Name 'Any' is not defined
11961203
to_process = [] # E: Need type annotation for variable

0 commit comments

Comments
 (0)