Skip to content

Commit

Permalink
Consider import * to be an explicit re-export
Browse files Browse the repository at this point in the history
Resolves python#11856
  • Loading branch information
hauntsaninja committed Dec 29, 2021
1 parent 3d20576 commit ee0e30f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
8 changes: 3 additions & 5 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2037,12 +2037,10 @@ def visit_import_all(self, i: ImportAll) -> None:
if self.process_import_over_existing_name(
name, existing_symbol, node, i):
continue
# In stub files, `from x import *` always reexports the symbols.
# In regular files, only if implicit reexports are enabled.
module_public = self.is_stub_file or self.options.implicit_reexport
# `from x import *` always reexports symbols
self.add_imported_symbol(name, node, i,
module_public=module_public,
module_hidden=not module_public)
module_public=True,
module_hidden=False)

else:
# Don't add any dummy symbols for 'from x import *' if 'x' is unknown.
Expand Down
14 changes: 1 addition & 13 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -1562,17 +1562,7 @@ __all__ = ('b',)
[out]
main:2: error: Module "other_module_2" does not explicitly export attribute "a"; implicit reexport disabled

[case testNoImplicitReexportStarConsideredImplicit]
# flags: --no-implicit-reexport
from other_module_2 import a
[file other_module_1.py]
a = 5
[file other_module_2.py]
from other_module_1 import *
[out]
main:2: error: Module "other_module_2" does not explicitly export attribute "a"; implicit reexport disabled

[case testNoImplicitReexportStarCanBeReexportedWithAll]
[case testNoImplicitReexportStarConsideredExplicit]
# flags: --no-implicit-reexport
from other_module_2 import a
from other_module_2 import b
Expand All @@ -1583,8 +1573,6 @@ b = 6
from other_module_1 import *
__all__ = ('b',)
[builtins fixtures/tuple.pyi]
[out]
main:2: error: Module "other_module_2" does not explicitly export attribute "a"; implicit reexport disabled

[case testNoImplicitReexportGetAttr]
# flags: --no-implicit-reexport --python-version 3.7
Expand Down

0 comments on commit ee0e30f

Please sign in to comment.