magicmethods
magicmethods copied to clipboard
Document __path__
This guide is a de-facto reference for all things that surrounded by double underscore, so it would be nice to see __path__
there as well.
Agreed, @techtonik I'm inclined to fork and add:
- Appendix 3: Magic Attributes (e.g.
__path__
__all__
) - Appendix 4: Magic File Names (e.g.
__init__.py
).
Thoughts?
Seems fine.
If a package’s init.py code defines a list named
__all__
, it is taken to be the list of module names that should be imported whenfrom package import *
is encountered. It is up to the package author to keep this list up-to-date
https://docs.python.org/3/tutorial/modules.html#importing-from-a-package
If the module is a package (either regular or namespace), the module object’s
__path__
attribute must be set. The value must be iterable, but may be empty if__path__
has no further significance. If__path__
is not empty, it must produce strings when iterated over. More details on the semantics of__path__
are given below.Non-package modules should not have a path attribute.
https://docs.python.org/3/reference/import.html#path
... https://docs.python.org/3/reference/import.html#import-related-module-attributes