-
Notifications
You must be signed in to change notification settings - Fork 6
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
Use __all__
to advertise public API.
#337
Conversation
Codecov Report
@@ Coverage Diff @@
## main #337 +/- ##
=======================================
Coverage 99.92% 99.92%
=======================================
Files 5 5
Lines 1369 1372 +3
=======================================
+ Hits 1368 1371 +3
Misses 1 1
Continue to review full report at Codecov.
|
Annoyingly, people who use python notebooks to explore libraries with tab completion (instead of reading documentation) will still see, and be able to access, non-public symbols. I believe the number of people who use notebooks like this is substantial.
|
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.
Looks good, but I don't know why we'd do this for anything other than the top-level init.py
Also, we need a new test module that does something like this one
(The strings in all aren't resolved until run time - this is the only way to be sure they aremeaningul)
demes/load_dump.py
Outdated
@@ -11,6 +11,17 @@ | |||
|
|||
import demes |
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.
Not clear to me why we'd have an __all__
in implementation-private submodules. We woulnd't encourage users to use from demes.load_dump import *
, would we?
IMO, this is more about what the public API is being advertised as, rather than caring about specific |
Sure, I agree noone should actually be using this, but I still don't see why you'd want to add |
In some sense you're right about not needing A possible further step (which I don't want to take) is to delete the non-public symbols from the modules so that they can't be imported even if one knows the name (E.g. like this: https://github.com/tensorflow/tensorflow/blob/e9de087fa7f59c39bbe12ac2c83c5547c83f746c/tensorflow/python/util/all_util.py#L86). |
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.
LGTM - just needs a test checking import * works, like I suggested, and something covering dir
9e0a277
to
2ad064d
Compare
Closes popsim-consortium#324. Note that non-public symbols are still accessible when referred to explicitly by name. But here we use the module-level __dir__() function to define which symbols are seen when using dir(<module-name>). This is a Python >= 3.7 only feature, but the function is just ignored on Python 3.6.
Closes #324.
Note that non-public symbols are still accessible, and that some
applications, such as iPython, will ignore
__all__
when offeringtab-completion suggestions.