Skip to content

Commit e4ff209

Browse files
committed
fix(11064): fix crash due to undefined cyclic import *
1 parent 9bd6517 commit e4ff209

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4628,7 +4628,7 @@ def add_imported_symbol(self,
46284628
symbol = SymbolTableNode(node.kind, node.node,
46294629
module_public=module_public,
46304630
module_hidden=module_hidden)
4631-
self.add_symbol_table_node(name, symbol, context)
4631+
self.add_symbol_table_node(name, symbol, context, can_defer=not self.final_iteration)
46324632

46334633
def add_unknown_imported_symbol(self,
46344634
name: str,

test-data/unit/check-modules.test

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3131,4 +3131,36 @@ main:2: error: Cannot find implementation or library stub for module named "blea
31313131
# flags: --ignore-missing-imports
31323132
import bleach.xyz
31333133
from bleach.abc import fgh
3134-
[file bleach/__init__.pyi]
3134+
[file bleach/__init__.pyi]
3135+
3136+
[case testCyclicUndefinedImportWithName]
3137+
import a
3138+
[file a.py]
3139+
from b import no_such_export
3140+
[file b.py]
3141+
from a import no_such_export # E: Module "a" has no attribute "no_such_export"
3142+
3143+
[case testCyclicUndefinedImportWithStar1]
3144+
import a
3145+
[file a.py]
3146+
from b import no_such_export # E: Module "b" has no attribute "no_such_export"
3147+
[file b.py]
3148+
from a import *
3149+
3150+
[case testCyclicUndefinedImportWithStar2]
3151+
import a
3152+
[file a.py]
3153+
from b import no_such_export # E: Module "b" has no attribute "no_such_export"
3154+
[file b.py]
3155+
from c import *
3156+
[file c.py]
3157+
from a import *
3158+
3159+
[case testCyclicUndefinedImportWithStar3]
3160+
import test1
3161+
[file test1.py]
3162+
from dir1 import *
3163+
[file dir1/__init__.py]
3164+
from .test2 import *
3165+
[file dir1/test2.py]
3166+
from test1 import aaaa # E: Module "test1" has no attribute "aaaa"

0 commit comments

Comments
 (0)