-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Support exported names starting with an underscore in __all__ #3746
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
Support exported names starting with an underscore in __all__ #3746
Conversation
mypy/server/astdiff.py
Outdated
@@ -57,7 +57,8 @@ def is_similar_node_shallow(n: SymbolTableNode, m: SymbolTableNode) -> bool: | |||
# type_override | |||
if (n.kind != m.kind | |||
or n.mod_id != m.mod_id | |||
or n.module_public != m.module_public): | |||
or n.module_public != m.module_public | |||
or n.module_public_even_with_underscore != m.module_public_even_with_underscore): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure of whether this should be included here or not, since it's affected by __all__
only. I would greatly appreciate if someone who has a better idea of the use of this function could comment on this.
Thanks for PR! Concerning your question on gitter about |
@@ -1483,7 +1486,8 @@ def visit_import_all(self, i: ImportAll) -> None: | |||
self.add_submodules_to_parent_modules(i_id, True) | |||
for name, node in m.names.items(): | |||
node = self.normalize_type_alias(node, i) | |||
if not name.startswith('_') and node.module_public: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't it possible to fix this by only changing the logic here? For example add a nested if
that ignores the check for underscore here if m.names
contains '__all__'
TBH, I don't really like inclusion of a new flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have access to __all__
here, not introducing a new flag does sound better! I wasn't sure of where we had access to what, so I was somewhat following how #1640 implemented __all__
originally.
Thank you for mentioning this, I'll change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we don't actually need to access its content, we just need to know that it is there, since in this case all names not in __all__
will have module_public = False
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right! Awesome, that's even better than what I misread you as saying - thanks!
Thanks to @ilevkivskyi for this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM, I will merge this later if there are no objections.
Thank you! |
Fixes #3745, if that's something we want to do.
This seemed like a fairly small change, so I went ahead and made this pull request. I'm not 100% sure the name
module_public_even_with_underscore
is best here, if there are any suggestions on this or any other part of the PR please mention them.I added a new variable with the default
False
since it seemed like a good way to add this without introducing more overhead on any code which doesn't use this feature. I don't know this codebase very well though, so if there is a better or more clean way to do this, that would be excellent.