diff --git a/pep-0382.txt b/pep-0382.txt index ff9abca2a..6b5b896e5 100644 --- a/pep-0382.txt +++ b/pep-0382.txt @@ -94,11 +94,15 @@ declarative approach is proposed here: A directory whose name ends with ``.pyp`` (for Python package) contains a portion of a package. The import statement is extended so that computes the package's -``__path__`` attribute for a package named ``P`` as consisting of all -directories named ``P.pyp``, plus optionally a single directory named -``P`` containing a file ``__init__.py``. If either of these are -found on the path of the parent package (or sys.path for a top-level -package), search for additional portions of the package continues. +``__path__`` attribute for a package named ``P`` as consisting of +optionally a single directory name ``P`` containing a file +``__init__.py``, plus all directories named ``P.pyp``, in the order in +which they are found in the parent's package ``__path__`` (or +``sys.path``). If either of these are found, search for additional +portions of the package continues. + +A directory may contain both a package in the ``P/__init__.py`` and +the ``P.pyp`` form. No other change to the importing mechanism is made; searching modules (including __init__.py) will continue to stop at the first module @@ -129,27 +133,22 @@ Finders need to support looking for \*.pth files in step 1 of above algorithm. To do so, a finder used as a path hook must support a method: - finder.is_package_portion(fullname) + finder.find_package_portion(fullname) This method will be called in the same manner as find_module, and it -must return True if there is a package portion with that name; False -if fullname indicates a subpackage/submodule that is not a package -portion; otherwise, it shall raise an ImportError. +must return an string to be added to the package's ``__path__``. +If the finder doesn't find a portion of the package, it shall return +``None``. Raising ``AttributeError`` from above call will be treated +as non-conformance with this PEP, and the exception will be ignored. +All other exceptions are reported. -If any \*.pyp directories are found, but no loader was returned from -find_module, a package is created and initialized with the path. - -If a loader was return, but no \*.pyp directories, load_module is -called as defined in PEP 302. - -If both \*.pyp directories where found, and a loader was returned, a -new method is called on the loader: - - loader.load_module_with_path(load_module, path) - -where the path parameter is the list that will become the __path__ -attribute of the new package. +A finder may report both success from ``find_module`` and from +``find_package_portion``, allowing for both a package containing +an ``__init__.py`` and a portion of the same package. +All strings returned from ``find_package_portion``, along with all +path names of ``.pyp`` directories are added to the new package's +``__path__``. Discussion ========== @@ -181,7 +180,7 @@ noticed that Jython could easily mistake a directory that is a Java package as being a Python package, if there is no need to declare Python packages. -packages can stop filling out the namespace package's __init__.py. As +Packages can stop filling out the namespace package's __init__.py. As a consequence, extend_path and declare_namespace become obsolete. Namespace packages can start providing non-trivial __init__.py @@ -195,15 +194,6 @@ mechanisms. extend_path will be adjusted to this specification; any other mechanism might cause portions to get added twice to __path__. -It has been proposed to also add this feature to Python 2.7. Given -that 2.x reaches its end-of-life, it is questionable whether the -addition of the feature would really do more good than harm (in having -users and tools starting to special-case 2.7). Prospective users of -this feature are encouraged to comment on this particular question. In -addition, Python 2.7 is in bug-fix mode now, so adding new features to -it would be a violation of the established policies. - - Copyright =========