-
-
Notifications
You must be signed in to change notification settings - Fork 3k
--no-implicit-reexport
should treat names in __all__
as exported
#7042
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
Comments
FWIW, I agree. I ran into this when enabling I also intuitively think
|
I didn't know about this issue. Is there a workaround we can add to the SDK? |
@untitaker Like @Zac-HD suggested in the Hypothesis issue, I just turned the feature off for |
Agreed that this looks like a bug. |
Anybody want to try to fix this? This doesn't sound very tricky. |
The natural expectation is that when a variable is explicitly added to a module's `__all__`, the module explicitly means to export it. Previously, this was not the case, and a `from [..] import [..] as [..]` reexport was required by `--no-implicit-export` even if the variable is listed in `__all__`. Fixes python#7042
The natural expectation is that when a variable is explicitly added to a module's `__all__`, the module explicitly means to export it. Previously, this was not the case, and a `from [..] import [..] as [..]` reexport was required by `--no-implicit-export` even if the variable is listed in `__all__`. Fixes python#7042 TODO: - Add more test cases (interaction with `import *` especially).
I started writing tests for the PR but there is a behavior I'm not sure about. Currently, star imports always reexport. That is, given # private_module.py
a = 1
# public_module.py
from private_module import * then This behavior is documented for stub files in PEP 484:
My question: should star-imports be considered explicit reexports also in regular (non-stub) files? Pro: consistent with stub files, less boilerplate for intentional reexports. Con: surprising, makes it impossible to use star imports in modules that want to control their exports. My personal preference is to not make them explicit reexports, but don't feel strongly; will implement which ever way is decided. |
I share your preference, though I would say it's strong for me. Brevity is a virtue for stub files, but for actual source code "explicit is better than implicit" - if something from a star-import is meant to be reexported, it can be added to |
My initial inclination was that they need to continue to be considered explicit, since it is a (perhaps unfortunate) common pattern to reexport everything. But thinking about it some more, now that mypy supports in-file configuration directives, it will be easy to disable So yeah, let's make it not considered an explicit reexport. |
The natural expectation is that when a variable is explicitly added to a module's `__all__`, the module explicitly means to export it. Previously, this was not the case, and a `from [..] import [..] as [..]` reexport was required by `--no-implicit-export` even if the variable is listed in `__all__`. Fixes python#7042
…bled Currently, in regular files, symbols imported into module A with `from B import *` are considered explicitly exported from module B as well, i.e. they are considered part of module's B public API. This behavior makes sense in stub files as a shorthand (and is specified in PEP 484), but for regular files I think it is better to be explicit: add the symbols to `__all__`: [A.py] from B import * import B __all__ = [...] + B.__all__ Further discussion: python#7042 (comment)
…bled Currently, in regular files, symbols imported into module A with `from B import *` are considered explicitly exported from module B as well, i.e. they are considered part of module's B public API. This behavior makes sense in stub files as a shorthand (and is specified in PEP 484), but for regular files I think it is better to be explicit: add the symbols to `__all__`. Further discussion: python#7042 (comment)
…abled (#7361) Based on #7099. Currently, in regular files, symbols imported into module A with `from B import *` are considered explicitly exported from module A as well, i.e. they are considered part of module's A public API. This behavior makes sense in stub files as a shorthand (and is specified in PEP 484), but for regular files I think it is better to be explicit: add the symbols to `__all__`. Fixes #7042 Further discussion: #7042 (comment)
From HypothesisWorks/hypothesis#2017, passing
--no-implicit-reexport
with Mypy 0.710 causeserror: Module 'hypothesis' has no attribute 'given'
- except that it does, andgiven
is listed in the__all__
attribute.IMO when
__all__
is present only those names should be considered explicitly re-exported, though taking the union of those and the from-import-x-as-x form would be reasonable too. Ignoring__all__
is pretty weird though!The text was updated successfully, but these errors were encountered: