Skip to content

Fix --no-implicit-reexport inconsistency #11707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,11 @@ def process_imported_symbol(self,
fullname: str,
module_public: bool,
context: ImportBase) -> None:
module_hidden = not module_public and fullname not in self.modules
module_hidden = not module_public and not (
# `from package import module` should work regardless of whether package
# re-exports module
isinstance(node.node, MypyFile) and fullname in self.modules
)

if isinstance(node.node, PlaceholderNode):
if self.final_iteration:
Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,24 @@ class C:

[builtins fixtures/module.pyi]

[case testReExportChildStubs3]
from util import mod
reveal_type(mod) # N: Revealed type is "def () -> package.mod.mod"

from util import internal_detail # E: Module "util" has no attribute "internal_detail"

[file package/__init__.pyi]
from .mod import mod as mod

[file package/mod.pyi]
class mod: ...

[file util.pyi]
from package import mod as mod
# stubs require explicit re-export
from package import mod as internal_detail
[builtins fixtures/module.pyi]

[case testNoReExportChildStubs]
import mod
from mod import C, D # E: Module "mod" has no attribute "C"
Expand Down