Skip to content

fix(11064): fix crash due to undefined cyclic import * #11346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4670,7 +4670,7 @@ def add_imported_symbol(self,
symbol = SymbolTableNode(node.kind, node.node,
module_public=module_public,
module_hidden=module_hidden)
self.add_symbol_table_node(name, symbol, context)
self.add_symbol_table_node(name, symbol, context, can_defer=not self.final_iteration)

def add_unknown_imported_symbol(self,
name: str,
Expand Down
34 changes: 33 additions & 1 deletion test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -3131,4 +3131,36 @@ main:2: error: Cannot find implementation or library stub for module named "blea
# flags: --ignore-missing-imports
import bleach.xyz
from bleach.abc import fgh
[file bleach/__init__.pyi]
[file bleach/__init__.pyi]

[case testCyclicUndefinedImportWithName]
import a
[file a.py]
from b import no_such_export
[file b.py]
from a import no_such_export # E: Module "a" has no attribute "no_such_export"

[case testCyclicUndefinedImportWithStar1]
import a
[file a.py]
from b import no_such_export # E: Module "b" has no attribute "no_such_export"
[file b.py]
from a import *

[case testCyclicUndefinedImportWithStar2]
import a
[file a.py]
from b import no_such_export # E: Module "b" has no attribute "no_such_export"
[file b.py]
from c import *
[file c.py]
from a import *

[case testCyclicUndefinedImportWithStar3]
import test1
[file test1.py]
from dir1 import *
[file dir1/__init__.py]
from .test2 import *
[file dir1/test2.py]
from test1 import aaaa # E: Module "test1" has no attribute "aaaa"