Skip to content
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 auto-filtering of members based on __all__ #78

Open
pawamoy opened this issue Jun 15, 2023 · 0 comments
Open

Support auto-filtering of members based on __all__ #78

pawamoy opened this issue Jun 15, 2023 · 0 comments
Labels
feature New feature or request

Comments

@pawamoy
Copy link
Member

pawamoy commented Jun 15, 2023

Is your feature request related to a problem? Please describe.
By convention, Python devs use __all__ both to control what gets imported by wildcard imports, and in the same sense, define which objects are public. Currently, all non-private members will be rendered by mkdocstrings, instead of members defined in __all__.

Describe the solution you'd like
An option (enabled by default?) to tell mkdocstrings to only render objects that are added to __all__.

Describe alternatives you've considered
/

Additional context
Discussed on Gitter:

Kludex (Marcelo Trylesinski)
can I only load docstrings from objects in __all__?

pawamoy
Not natively I'm afraid. __all__ is meant for wildcard imports (explicit re-exports), so we use it like such, and to know if an alias should be resolved. There's no way yet to mark objects as "public" except for the underscore prefix convention (marking objects as private, therefore marking the rest as public)

Kludex (Marcelo Trylesinski)
thanks

dhirschfeld (Dave Hirschfeld)
__all__ is used for wildcard imports, but it's also a fairly strong convention that it denotes the public api of a module
What else is an import * for, other than import all public functions
Naming a function with an _ prefix implicitly defines it as private, by convention. Also, by convention, the public api of a module can be explicitly defined by listing it in __all__
I'm ok if tools want to ignore this long-standing convention however I think they should at least make respecting __all__ as the explicitly defined public api of a module an option
I'm not sure where the distinction between "explicitly re-exported" and public comes from - to me it is absolutely synonymous with "public"
...which means that if it's not "explicitly exported" it's intended to be private to that module... however it is named.

pawamoy
well, something could be public but not re-exported (for example to avoid ambiguity or conflicts when other modules provide an object with the same name)
I'm not against adding an option to use __all__ as the list of public objects, it's just that I'm not really satisfied with the whole situation :)
I guess the fact that from thing import * without __all__ defined imports all objects except those starting with an underscore is a strong argument in favor of "__all__ defines what is public"
@pawamoy pawamoy added the feature New feature or request label Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant