Skip to content

Commit 85129b1

Browse files
committed
Also fix #4429
1 parent 8091724 commit 85129b1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mypy/semanal.py

+3
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,9 @@ def dereference_module_cross_ref(
15681568
# nothing).
15691569
while node and isinstance(node.node, ImportedName):
15701570
fullname = node.node.fullname()
1571+
if fullname in self.modules:
1572+
# This is a module reference.
1573+
return SymbolTableNode(MODULE_REF, self.modules[fullname])
15711574
if fullname in seen:
15721575
# Looks like a reference cycle. Just break it.
15731576
# TODO: Generate a more specific error message.

test-data/unit/check-modules.test

+19
Original file line numberDiff line numberDiff line change
@@ -2152,3 +2152,22 @@ class Two:
21522152
pass
21532153
[out]
21542154
tmp/m/two.py:3: error: Revealed type is 'Union[builtins.int, builtins.str]'
2155+
2156+
[case testImportCycleSpecialCase]
2157+
import p
2158+
[file p/__init__.py]
2159+
from . import a
2160+
from . import b
2161+
reveal_type(a.foo())
2162+
[file p/a.py]
2163+
import p
2164+
def foo() -> int: pass
2165+
[file p/b.py]
2166+
import p
2167+
2168+
def run() -> None:
2169+
reveal_type(p.a.foo())
2170+
[builtins fixtures/module.pyi]
2171+
[out]
2172+
tmp/p/b.py:4: error: Revealed type is 'builtins.int'
2173+
tmp/p/__init__.py:3: error: Revealed type is 'builtins.int'

0 commit comments

Comments
 (0)