-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix: --include-private issue (#16808) #16822
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
base: master
Are you sure you want to change the base?
Fix: --include-private issue (#16808) #16822
Conversation
* (fix): when --include-private is not passed stubgen omits packages and modules which names start with "_" and do not end with "__"
This comment has been minimized.
This comment has been minimized.
* (chore): add missing type hints * (docs): add docsting
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thank you for working on this. |
* (fix): add checking if --include-private passed
Thank you for the feedback. |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
I think from ._private import Base
class Derived(Base): … If you don’t generate |
@hamdanal, thank you for the detailed explanation. Indeed, avoiding modules Tbh, so far, I don't have strong arguments for implementing a flag, like you said, Since issue #16808 has been opened, shouldn't we mention this in the documentation somewhere? |
OP of #16808 here. @hamdanal points out correctly that any object in a Python module may be available via multiple import paths, some of which may contain leading underscored and some of which may not. Some may consider it bad style to expose objects in two such paths, but it does indeed happen. I think we can agree that those methods are to be considered public, just like objects which are solely available via leading-underscored paths are to be considered private. I don't think we should differentiate between a private module and a private function. Two flags Instead, a proper solution is to check in |
This commit aims to close #16808.
Let me introduce you to my struggling.
At first I decided that this happens because of
is_private_name()
. Indeed, when stubgen iterates over nodes via visitor and callsis_private_name()
it checks only node's (function's in our case) name:stubutil.py
As you can see from the above,
is_private_name()
checks onlyname
without considering the fullname.However, if we modify it and make it check fqn, the problem would still persist — stubfiles would be created and there would be nothing (empty files).
Then, to make stubgen omit those packages/modules entirely, I decided to incorporate this logic into
generate_stub_for_py_module()
.And it worked, checked manually on structure like the below.
The output:
Seems to be OK.