[Python-checkins] peps: Added dynamic path calculation.

eric.smith python-checkins at python.org
Fri May 11 18:57:04 CEST 2012


http://hg.python.org/peps/rev/3775ecd04d4d
changeset:   4369:3775ecd04d4d
user:        Eric V. Smith <eric at trueblade.com>
date:        Fri May 11 12:56:56 2012 -0400
summary:
  Added dynamic path calculation.

files:
  pep-0420.txt |  33 ++++++++++++++++-----------------
  1 files changed, 16 insertions(+), 17 deletions(-)


diff --git a/pep-0420.txt b/pep-0420.txt
--- a/pep-0420.txt
+++ b/pep-0420.txt
@@ -140,12 +140,6 @@
 
  * Does not have a ``__file__`` attribute.
 
-There is no mechanism to automatically recompute the ``__path__`` if
-``sys.path`` is altered after a namespace package has already been
-created.  However, existing namespace utilities (like
-``pkgutil.extend_path``) can be used to update them explicitly if
-desired.
-
 Note that if "import foo" is executed and "foo" is found as a
 namespace package (using the above rules), then "foo" is immediately
 created as a package.  The creation of the namespace package is not
@@ -159,6 +153,20 @@
 path separator (typically a slash or backslash, depending on the
 platform).
 
+Dynamic path computation
+------------------------
+
+A namespace package's ``__path__`` will be recomputed if the value of
+the parent path changes. In order for this feature to work, the parent
+path must be modified in-place, not replaced with a new object. For
+example, for top-level namespace packages, this will work::
+
+    sys.path.append('new-dir')
+
+But this will not::
+
+    sys.path = sys.path + ['new-dir']
+
 Impact on Import Finders and Loaders
 ------------------------------------
 
@@ -265,12 +273,6 @@
 
   4. This will also be addressed in PEP 395.
 
-Phillip Eby asked about auto-updating of ``__path__``, instead of it
-being a simple list [5]_.  It is the intent of this PEP to get the
-simplest possible solution working.  It will be possible at a later
-date to add such features.  Several possible ways to do so were
-discussed in the referenced email thread.
-
 ``find_module`` versus ``find_loader``
 --------------------------------------
 
@@ -288,7 +290,7 @@
 implement the ``find_loader`` method, described above.
 
 The use case for supporting multiple portions per ``find_loader`` call
-is given in [6]_.
+is given in [5]_.
 
 
 Module reprs
@@ -345,10 +347,7 @@
 .. [4] Nick Coghlan's response to his initial objections
        (http://mail.python.org/pipermail/import-sig/2012-April/000464.html)
 
-.. [5] Phillip Eby's question about auto-updating __path__
-       (http://mail.python.org/pipermail/import-sig/2012-April/000468.html)
-
-.. [6] Use case for multiple portions per ``find_loader`` call
+.. [5] Use case for multiple portions per ``find_loader`` call
        (http://mail.python.org/pipermail/import-sig/2012-May/000585.html)
 
 Copyright

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


More information about the Python-checkins mailing list