From efeeeb0c6cedba649352a271983e19f8ad6132a4 Mon Sep 17 00:00:00 2001 From: Yurii Karabas <1998uriyyo@gmail.com> Date: Sun, 29 Jan 2023 16:03:38 +0200 Subject: [PATCH 1/2] Fix internal crash when resolve same partial type twice --- mypy/checkexpr.py | 3 ++- test-data/unit/check-inference.test | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index dfac5be27d95..0ec7d1097da8 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -630,7 +630,8 @@ def try_infer_partial_type(self, e: CallExpr) -> None: return var, partial_types = ret typ = self.try_infer_partial_value_type_from_call(e, callee.name, var) - if typ is not None: + # Var may be deleted from partial_types in try_infer_partial_value_type_from_call + if typ is not None and var in partial_types: var.type = typ del partial_types[var] elif isinstance(callee.expr, IndexExpr) and isinstance(callee.expr.base, RefExpr): diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index adf4a7b60420..be9e22416a49 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -1940,6 +1940,12 @@ class A: [out] main:4: error: "None" has no attribute "__iter__" (not iterable) +[case testPartialTypeErrorSpecialCase4] +# This used to crash. +arr = [] +arr.append(arr.append(1)) +[out] +main:3: error: "List[int]" has no attribute "append" -- Multipass -- --------- From 999453b06d60d3d16ae14df90c9a7652364393d7 Mon Sep 17 00:00:00 2001 From: Yurii Karabas <1998uriyyo@gmail.com> Date: Sun, 29 Jan 2023 18:08:58 +0200 Subject: [PATCH 2/2] Add fixture to correctly show error message --- test-data/unit/check-inference.test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 541672015979..fc8113766f1a 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -1955,8 +1955,9 @@ main:4: error: "None" has no attribute "__iter__" (not iterable) # This used to crash. arr = [] arr.append(arr.append(1)) +[builtins fixtures/list.pyi] [out] -main:3: error: "List[int]" has no attribute "append" +main:3: error: "append" of "list" does not return a value -- Multipass -- ---------