Skip to content

Commit ec11a50

Browse files
committed
Fix an aststrip crash
Bug found testing on Zulip. Don't blithely index into self.names, since stripping ImportAll deletes entries.
1 parent 22ee713 commit ec11a50

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

mypy/server/aststrip.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ def visit_import(self, node: Import) -> None:
213213
for name, as_name in node.ids:
214214
imported_name = as_name or name
215215
initial = imported_name.split('.')[0]
216-
symnode = self.names[initial]
217-
symnode.kind = UNBOUND_IMPORTED
218-
symnode.node = None
216+
self.names[initial] = SymbolTableNode(UNBOUND_IMPORTED, None)
219217

220218
def visit_import_all(self, node: ImportAll) -> None:
221219
# Imports can include both overriding symbols and fresh ones,

test-data/unit/fine-grained-modules.test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,40 @@ T = TypeVar('T')
16221622
[out]
16231623
==
16241624

1625+
[case testImportStarOverlap2]
1626+
from b import *
1627+
import typing
1628+
def foo(x: typing.List[int]) -> int:
1629+
return x[0]
1630+
[file b.py]
1631+
import typing
1632+
z = 10
1633+
[file b.py.2]
1634+
import typing
1635+
z = '10'
1636+
[builtins fixtures/list.pyi]
1637+
[out]
1638+
==
1639+
1640+
1641+
[case testImportStarOverlap3]
1642+
from b import *
1643+
from c import typing
1644+
def foo(x: typing.List[int]) -> int:
1645+
return x[0]
1646+
[file b.py]
1647+
import typing
1648+
z = 10
1649+
[file b.py.2]
1650+
import typing
1651+
z = '10'
1652+
[file c.py]
1653+
import typing
1654+
z = 10
1655+
[builtins fixtures/list.pyi]
1656+
[out]
1657+
==
1658+
16251659

16261660
[case testImportPartialAssign]
16271661
import a

0 commit comments

Comments
 (0)