Skip to content

Commit d168b6d

Browse files
authored
Fix --no-implicit-reexport inconsistency (#11707)
Fixes #11706 Co-authored-by: hauntsaninja <>
1 parent b6c8f03 commit d168b6d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

mypy/semanal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,11 @@ def process_imported_symbol(self,
19061906
fullname: str,
19071907
module_public: bool,
19081908
context: ImportBase) -> None:
1909-
module_hidden = not module_public and fullname not in self.modules
1909+
module_hidden = not module_public and not (
1910+
# `from package import module` should work regardless of whether package
1911+
# re-exports module
1912+
isinstance(node.node, MypyFile) and fullname in self.modules
1913+
)
19101914

19111915
if isinstance(node.node, PlaceholderNode):
19121916
if self.final_iteration:

test-data/unit/check-modules.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,24 @@ class C:
19101910

19111911
[builtins fixtures/module.pyi]
19121912

1913+
[case testReExportChildStubs3]
1914+
from util import mod
1915+
reveal_type(mod) # N: Revealed type is "def () -> package.mod.mod"
1916+
1917+
from util import internal_detail # E: Module "util" has no attribute "internal_detail"
1918+
1919+
[file package/__init__.pyi]
1920+
from .mod import mod as mod
1921+
1922+
[file package/mod.pyi]
1923+
class mod: ...
1924+
1925+
[file util.pyi]
1926+
from package import mod as mod
1927+
# stubs require explicit re-export
1928+
from package import mod as internal_detail
1929+
[builtins fixtures/module.pyi]
1930+
19131931
[case testNoReExportChildStubs]
19141932
import mod
19151933
from mod import C, D # E: Module "mod" has no attribute "C"

0 commit comments

Comments
 (0)