Skip to content

Commit 332616c

Browse files
hauntsaninjauriyyo
andauthored
[1.0 backport] Fix internal crash when resolve same partial type twice (#14552) (#14553)
Fixes: #14548 Fixed case when untyped list item type resolving can lead to an internal crash. Code to reproduce this issue: ```py arr = [] arr.append(arr.append(1)) ``` Basically, the issue is that after the first resolving of `arr.append` method, `var` is deleted from `partial_types`, and as war as `arr.append` is a nested call we try to delete the same `var` that was already deleted. Co-authored-by: Yurii Karabas <[email protected]>
1 parent b7c850c commit 332616c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

mypy/checkexpr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ def try_infer_partial_type(self, e: CallExpr) -> None:
895895
return
896896
var, partial_types = ret
897897
typ = self.try_infer_partial_value_type_from_call(e, callee.name, var)
898-
if typ is not None:
898+
# Var may be deleted from partial_types in try_infer_partial_value_type_from_call
899+
if typ is not None and var in partial_types:
899900
var.type = typ
900901
del partial_types[var]
901902
elif isinstance(callee.expr, IndexExpr) and isinstance(callee.expr.base, RefExpr):

test-data/unit/check-inference.test

+7
Original file line numberDiff line numberDiff line change
@@ -1951,6 +1951,13 @@ class A:
19511951
[out]
19521952
main:4: error: "None" has no attribute "__iter__" (not iterable)
19531953

1954+
[case testPartialTypeErrorSpecialCase4]
1955+
# This used to crash.
1956+
arr = []
1957+
arr.append(arr.append(1))
1958+
[builtins fixtures/list.pyi]
1959+
[out]
1960+
main:3: error: "append" of "list" does not return a value
19541961

19551962
-- Multipass
19561963
-- ---------

0 commit comments

Comments
 (0)