magicmethods icon indicating copy to clipboard operation
magicmethods copied to clipboard

Document __path__

Open techtonik opened this issue 10 years ago • 4 comments

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.

techtonik avatar Jul 19 '14 20:07 techtonik

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?

BobStein avatar Mar 20 '16 18:03 BobStein

Seems fine.

techtonik avatar Mar 20 '16 20:03 techtonik

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 when from 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

westurner avatar Feb 21 '19 14:02 westurner

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

westurner avatar Feb 21 '19 14:02 westurner