Update PEP 302 integration. Drop 2.7 discussion.
This commit is contained in:
parent
51e68d9af8
commit
84efc5c290
54
pep-0382.txt
54
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.
|
with ``.pyp`` (for Python package) contains a portion of a package.
|
||||||
|
|
||||||
The import statement is extended so that computes the package's
|
The import statement is extended so that computes the package's
|
||||||
``__path__`` attribute for a package named ``P`` as consisting of all
|
``__path__`` attribute for a package named ``P`` as consisting of
|
||||||
directories named ``P.pyp``, plus optionally a single directory named
|
optionally a single directory name ``P`` containing a file
|
||||||
``P`` containing a file ``__init__.py``. If either of these are
|
``__init__.py``, plus all directories named ``P.pyp``, in the order in
|
||||||
found on the path of the parent package (or sys.path for a top-level
|
which they are found in the parent's package ``__path__`` (or
|
||||||
package), search for additional portions of the package continues.
|
``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
|
No other change to the importing mechanism is made; searching modules
|
||||||
(including __init__.py) will continue to stop at the first module
|
(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
|
algorithm. To do so, a finder used as a path hook must support a
|
||||||
method:
|
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
|
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
|
must return an string to be added to the package's ``__path__``.
|
||||||
if fullname indicates a subpackage/submodule that is not a package
|
If the finder doesn't find a portion of the package, it shall return
|
||||||
portion; otherwise, it shall raise an ImportError.
|
``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
|
A finder may report both success from ``find_module`` and from
|
||||||
find_module, a package is created and initialized with the path.
|
``find_package_portion``, allowing for both a package containing
|
||||||
|
an ``__init__.py`` and a portion of the same package.
|
||||||
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.
|
|
||||||
|
|
||||||
|
All strings returned from ``find_package_portion``, along with all
|
||||||
|
path names of ``.pyp`` directories are added to the new package's
|
||||||
|
``__path__``.
|
||||||
|
|
||||||
Discussion
|
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
|
package as being a Python package, if there is no need to declare
|
||||||
Python packages.
|
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.
|
a consequence, extend_path and declare_namespace become obsolete.
|
||||||
|
|
||||||
Namespace packages can start providing non-trivial __init__.py
|
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
|
any other mechanism might cause portions to get added twice to
|
||||||
__path__.
|
__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
|
Copyright
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue