Clarify path scanning logic.
This commit is contained in:
parent
83e5ef1646
commit
9ca3720073
27
pep-0420.txt
27
pep-0420.txt
|
@ -114,19 +114,30 @@ namespace package creation. There will be no marker file or directory
|
|||
for specifing a namespace package.
|
||||
|
||||
During import processing, the import machinery will continue to
|
||||
iterate over the parent path as it does in Python 3.2. While looking
|
||||
for a module or package named "foo":
|
||||
iterate over each directory in the parent path as it does in Python
|
||||
3.2. While looking for a module or package named "foo", for each
|
||||
directory in the parent path:
|
||||
|
||||
* If ``foo/__init__.py`` is found, a regular package is imported.
|
||||
* If not, but ``foo.{py,pyc,so,pyd}`` is found, a module is imported.
|
||||
* If not, but ``foo`` is found and is a directory, it is recorded.
|
||||
* If ``<directory>/foo/__init__.py`` is found, a regular package is
|
||||
imported and returned.
|
||||
|
||||
If the scan along the parent path completes without finding a module
|
||||
or package and at least one directory was recorded, then a namespace
|
||||
package is created. The new namespace package:
|
||||
* If not, but ``<directory>/foo.{py,pyc,so,pyd}`` is found, a module
|
||||
is imported and returned.
|
||||
|
||||
* If not, but ``<directory>/foo`` is found and is a directory, it is
|
||||
recorded and the scan continues with the next directory in the
|
||||
parent path.
|
||||
|
||||
* Otherwise the scan continues with the next directory in the parent
|
||||
path.
|
||||
|
||||
If the scan completes without returning a module or package, and at
|
||||
least one directory was recorded, then a namespace package is created.
|
||||
The new namespace package:
|
||||
|
||||
* Has a ``__file__`` attribute set to the first directory that was
|
||||
found during the scan, including the trailing path separator.
|
||||
|
||||
* Has a ``__path__`` attribute set to the list of directories there
|
||||
were found and recorded during the scan.
|
||||
|
||||
|
|
Loading…
Reference in New Issue