8000 Fix misindented `del` statement. (#3954) · python/mypy@3db1451 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3db1451

Browse files
authored
Fix misindented del statement. (#3954)
Fixes #3892. Everywhere we infer the correct type for a partially-typed variable, we do two things: set var.type and delete var from partial_tyes. However in one place (try_infer_partial_type_from_indexed_assignment()) the var.type assignment was skipped if the current node was deferred but the deletion was done unconditionally. This caused the partial type to remain in a place where serialization could not handle it.
1 parent a771113 commit 3db1451

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ def try_infer_partial_type_from_indexed_assignment(
19891989
if not self.current_node_deferred:
19901990
var.type = self.named_generic_type('builtins.dict',
19911991
[full_key_type, full_value_type])
1992-
del partial_types[var]
1992+
del partial_types[var]
19931993

19941994
def visit_expression_stmt(self, s: ExpressionStmt) -> None:
19951995
self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)

test-data/unit/check-incremental.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,3 +2951,21 @@ def foo(a: int, b: int) -> str:
29512951
[out1]
29522952
[out2]
29532953
tmp/b.py:2: error: Incompatible return value type (got "int", expected "str")
2954+
2955+
[case testCrashWithPartialGlobalAndCycle]
2956+
import bar
2957+
2958+
[file foo.py]
2959+
import bar
2960+
my_global_dict = {} # type: ignore
2961+
def external_func_0() -> None:
2962+
global my_global_dict
2963+
bar.external_list
2964+
my_global_dict[12] = 0
2965+
2966+
[file bar.py]
2967+
import foo
2968+
2969+
external_list = [0]
2970+
2971+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)
0