Skip to content

Commit e14cb14

Browse files
authored
Fix re-exporting __all__ in a stub file (#10382)
Propagate the value of `__all__` from the imported module. Fixes #10381.
1 parent 352b0a9 commit e14cb14

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

mypy/semanal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,8 @@ def visit_import_from(self, imp: ImportFrom) -> None:
17581758
# precedence, but doesn't seem to be important in most use cases.
17591759
node = SymbolTableNode(GDEF, self.modules[fullname])
17601760
else:
1761+
if id == as_id == '__all__' and module_id in self.export_map:
1762+
self.all_exports[:] = self.export_map[module_id]
17611763
node = module.names.get(id)
17621764

17631765
missing_submodule = False

test-data/unit/check-modules.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,3 +2825,21 @@ from mystery import a, b as b, c as d
28252825
[out]
28262826
tmp/stub.pyi:1: error: Cannot find implementation or library stub for module named "mystery"
28272827
tmp/stub.pyi:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
2828+
2829+
[case testReExportAllInStub]
2830+
from m1 import C
2831+
from m1 import D # E: Module "m1" has no attribute "D"
2832+
C()
2833+
C(1) # E: Too many arguments for "C"
2834+
[file m1.pyi]
2835+
from m2 import *
2836+
[file m2.pyi]
2837+
from m3 import *
2838+
from m3 import __all__ as __all__
2839+
class D: pass
2840+
[file m3.pyi]
2841+
from m4 import C as C
2842+
__all__ = ['C']
2843+
[file m4.pyi]
2844+
class C: pass
2845+
[builtins fixtures/list.pyi]

0 commit comments

Comments
 (0)