mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
40b22d0661
commit
27e27f7ee1
6 changed files with 3471 additions and 3223 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue