Skip to content

Commit 3cc7e2e

Browse files
committed
Also update UNBOUND_IMPORTED Name expressions.
1 parent 9f36fec commit 3cc7e2e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

mypy/semanal_pass3.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,23 @@ def visit_import_from(self, imp: ImportFrom) -> None:
268268
for id, as_id in imp.names:
269269
my_node = self.sem.globals.get(as_id or id)
270270
src_node = module.names.get(id)
271+
# Fixup remaining UNBOUND_IMPORTED nodes from import cycles
271272
if my_node and src_node and my_node.kind == UNBOUND_IMPORTED:
272273
my_node.kind = src_node.kind
273274
my_node.node = src_node.node
274275
my_node.type_override = src_node.type_override
275276
my_node.normalized = src_node.normalized
276277
my_node.alias_tvars = src_node.alias_tvars
277278

279+
def visit_name_expr(self, expr: NameExpr) -> None:
280+
# Fixup remaining UNBOUND_IMPORTED nodes from import cycles
281+
if expr.kind == UNBOUND_IMPORTED:
282+
n = self.sem.lookup(expr.name, expr)
283+
if n:
284+
expr.kind = n.kind
285+
expr.node = n.node
286+
expr.fullname = n.fullname
287+
278288
# Helpers
279289

280290
def perform_transform(self, node: Union[Node, SymbolTableNode],

test-data/unit/check-modules.test

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,16 +1947,20 @@ main:3: error: Revealed type is 'Any'
19471947

19481948
[case testImportCycle]
19491949
from m import One
1950-
reveal_type(One) # E: Revealed type is 'def () -> m.one.One'
1950+
reveal_type(One)
19511951
[file m/__init__.py]
19521952
from .one import One
19531953
from .two import Two
1954-
reveal_type(One) # E: Revealed type is 'def () -> m.one.One'
1954+
reveal_type(One)
19551955
[file m/one.py]
19561956
class One:
19571957
pass
19581958
[file m/two.py]
19591959
from m import One
1960-
reveal_type(One) # E: Revealed type is 'def () -> m.one.One'
1960+
reveal_type(One)
19611961
class Two:
19621962
pass
1963+
[out]
1964+
tmp/m/two.py:2: error: Revealed type is 'def () -> m.one.One'
1965+
tmp/m/__init__.py:3: error: Revealed type is 'def () -> m.one.One'
1966+
main:2: error: Revealed type is 'def () -> m.one.One'

0 commit comments

Comments
 (0)