Skip to content

Commit 67df116

Browse files
authored
Fix crash on star import of redefinition (#20333)
Fixes #20327 Fix is trivial, do not grab various internal/temporary symbols with star imports. This may create an invalid cross-reference (and is generally dangerous). Likely, this worked previously because we processed all fresh modules in queue, not just the dependencies of current SCC.
1 parent dec6528 commit 67df116

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

mypy/semanal.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,6 +3201,10 @@ def visit_import_all(self, i: ImportAll) -> None:
32013201
# namespace is incomplete.
32023202
self.mark_incomplete("*", i)
32033203
for name, node in m.names.items():
3204+
if node.no_serialize:
3205+
# This is either internal or generated symbol, skip it to avoid problems
3206+
# like accidental name conflicts or invalid cross-references.
3207+
continue
32043208
fullname = i_id + "." + name
32053209
self.set_future_import_flags(fullname)
32063210
# if '__all__' exists, all nodes not included have had module_public set to

test-data/unit/check-incremental.test

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7596,3 +7596,33 @@ X = 0
75967596
tmp/a.py:6: error: "object" has no attribute "dtypes"
75977597
[out2]
75987598
tmp/a.py:2: error: "object" has no attribute "dtypes"
7599+
7600+
[case testStarImportCycleRedefinition]
7601+
import m
7602+
7603+
[file m.py]
7604+
import a
7605+
7606+
[file m.py.2]
7607+
import a
7608+
reveal_type(a.C)
7609+
7610+
[file a/__init__.py]
7611+
from a.b import *
7612+
from a.c import *
7613+
x = 1
7614+
7615+
[file a/b.py]
7616+
from other import C
7617+
from a.c import y
7618+
class C: ... # type: ignore
7619+
7620+
[file a/c.py]
7621+
from other import C
7622+
from a import x
7623+
y = 1
7624+
7625+
[file other.py]
7626+
class C: ...
7627+
[out2]
7628+
tmp/m.py:2: note: Revealed type is "def () -> other.C"

0 commit comments

Comments
 (0)