Clarify path scanning logic.

This commit is contained in:
Eric V. Smith 2012-05-02 11:16:48 -04:00
parent 83e5ef1646
commit 9ca3720073
1 changed files with 19 additions and 8 deletions

View File

@ -114,19 +114,30 @@ namespace package creation. There will be no marker file or directory
for specifing a namespace package. for specifing a namespace package.
During import processing, the import machinery will continue to During import processing, the import machinery will continue to
iterate over the parent path as it does in Python 3.2. While looking iterate over each directory in the parent path as it does in Python
for a module or package named "foo": 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 ``<directory>/foo/__init__.py`` is found, a regular package is
* If not, but ``foo.{py,pyc,so,pyd}`` is found, a module is imported. imported and returned.
* If not, but ``foo`` is found and is a directory, it is recorded.
If the scan along the parent path completes without finding a module * If not, but ``<directory>/foo.{py,pyc,so,pyd}`` is found, a module
or package and at least one directory was recorded, then a namespace is imported and returned.
package is created. The new namespace package:
* 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 * Has a ``__file__`` attribute set to the first directory that was
found during the scan, including the trailing path separator. found during the scan, including the trailing path separator.
* Has a ``__path__`` attribute set to the list of directories there * Has a ``__path__`` attribute set to the list of directories there
were found and recorded during the scan. were found and recorded during the scan.