Skip to content

Commit e3a3a48

Browse files
JukkaLmsullivan
authored andcommitted
Fine-grained: Fix hang due to nested class (#4728)
This works around the problem but doesn't fully resolve the underlying issue. Fixes #4612.
1 parent 6f6297d commit e3a3a48

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

mypy/semanal.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,15 @@ def setup_class_def_analysis(self, defn: ClassDef) -> None:
10661066
if kind == LDEF:
10671067
# We need to preserve local classes, let's store them
10681068
# in globals under mangled unique names
1069-
local_name = defn.info._fullname + '@' + str(defn.line)
1070-
defn.info._fullname = self.cur_mod_id + '.' + local_name
1069+
#
1070+
# TODO: Putting local classes into globals breaks assumptions in fine-grained
1071+
# incremental mode and we should avoid it.
1072+
if '@' not in defn.info._fullname:
1073+
local_name = defn.info._fullname + '@' + str(defn.line)
1074+
defn.info._fullname = self.cur_mod_id + '.' + local_name
1075+
else:
1076+
# Preserve name from previous fine-grained incremental run.
1077+
local_name = defn.info._fullname
10711078
defn.fullname = defn.info._fullname
10721079
self.globals[local_name] = node
10731080

test-data/unit/fine-grained.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,3 +2832,22 @@ class C(Enum):
28322832
==
28332833
a.py:4: error: Argument 1 to "f" has incompatible type "C"; expected "int"
28342834
a.py:5: error: Argument 1 to "f" has incompatible type "C"; expected "int"
2835+
2836+
[case testRefreshNestedClassWithSelfReference]
2837+
import a
2838+
[file a.py]
2839+
import b
2840+
2841+
def f(self) -> None:
2842+
b.y
2843+
class C:
2844+
z: C
2845+
[file b.py]
2846+
y = 0
2847+
[file b.py.2]
2848+
y = ''
2849+
[file b.py.3]
2850+
y = 0
2851+
[out]
2852+
==
2853+
==

0 commit comments

Comments
 (0)