[Python-checkins] peps: Clarify path scanning logic.

eric.smith python-checkins at python.org
Wed May 2 17:57:35 CEST 2012


http://hg.python.org/peps/rev/95cc28d462fd
changeset:   4346:95cc28d462fd
parent:      4344:d06e6520e92e
user:        Eric V. Smith <eric at trueblade.com>
date:        Wed May 02 11:16:48 2012 -0400
summary:
  Clarify path scanning logic.

files:
  pep-0420.txt |  27 +++++++++++++++++++--------
  1 files changed, 19 insertions(+), 8 deletions(-)


diff --git a/pep-0420.txt b/pep-0420.txt
--- a/pep-0420.txt
+++ b/pep-0420.txt
@@ -114,19 +114,30 @@
 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.
 

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list