summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-10-18 15:39:04 (GMT)
committerBrett Cannon <brett@python.org>2013-10-18 15:39:04 (GMT)
commit27e27f7ee1f366e52cfd576b427e923190b6202e (patch)
tree895d1caeba83a4151556fdb06fcad6141bd49f12 /Doc
parent40b22d0661c45ac350a7252a32ef665b81b1643c (diff)
downloadcpython-27e27f7ee1f366e52cfd576b427e923190b6202e.zip
cpython-27e27f7ee1f366e52cfd576b427e923190b6202e.tar.gz
cpython-27e27f7ee1f366e52cfd576b427e923190b6202e.tar.bz2
Issue #18416: Have importlib.machinery.PathFinder treat '' as the cwd
and stop importlib.machinery.FileFinder treating '' as '.'. Previous PathFinder transformed '' into '.' which led to __file__ for modules imported from the cwd to always be relative paths. This meant the values of the attribute were wrong as soon as the cwd changed. This change now means that as long as the site module is run (which makes all entries in sys.path absolute) then all values for __file__ will also be absolute unless it's for __main__ when specified by file path in a relative way (modules imported by runpy will have an absolute path). Now that PathFinder is no longer treating '' as '.' it only makes sense for FileFinder to stop doing so as well. Now no transformation is performed for the directory given to the __init__ method. Thanks to Madison May for the initial patch.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/importlib.rst7
-rw-r--r--Doc/whatsnew/3.4.rst11
2 files changed, 18 insertions, 0 deletions
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index 4cc4d10..566eb7a 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -722,6 +722,10 @@ find and load modules.
Calls :meth:`importlib.abc.PathEntryFinder.invalidate_caches` on all
finders stored in :attr:`sys.path_importer_cache`.
+ .. versionchanged:: 3.4
+ Calls objects in :data:sys.path_hooks with the current working directory
+ for ``''`` (i.e. the empty string).
+
.. class:: FileFinder(path, \*loader_details)
@@ -748,6 +752,9 @@ find and load modules.
.. versionadded:: 3.3
+ .. versionchange:: 3.4
+ The empty string is no longer special-cased to be changed into ``'.'``.
+
.. attribute:: path
The path the finder will search in.
diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst
index d7a6b9c..01e9259 100644
--- a/Doc/whatsnew/3.4.rst
+++ b/Doc/whatsnew/3.4.rst
@@ -675,3 +675,14 @@ that may require changes to your code.
:c:func:`PyMem_RawRealloc`, or *NULL* if an error occurred, instead of a
string allocated by :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`.
+* :cls:`importlib.machinery.PathFinder` now passes on the current working
+ directory to objects in :data:`sys.path_hooks` for the empty string. This
+ results in :data:`sys.path_importer_cache` never containing ``''``, thus
+ iterating through :data:`sys.path_importer_cache` based on :data:`sys.path`
+ will not find all keys. A module's ``__file__`` when imported in the current
+ working directory will also now have an absolute path, including when using
+ ``-m`` with the interpreter (this does not influence when the path to a file
+ is specified on the command-line).
+
+* :cls:`importlib.machinery.FileFinder` no longer special-cases the empty string
+ to be changed to ``'.'``.