Skip to content

Commit 23822e2

Browse files
authored
bpo-44070: No longer eagerly makes import filenames absolute, except for extension modules (GH-26025)
1 parent fbd9b99 commit 23822e2

4 files changed

Lines changed: 1839 additions & 1836 deletions

File tree

Lib/importlib/_bootstrap_external.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,6 @@ def spec_from_file_location(name, location=None, *, loader=None,
718718
pass
719719
else:
720720
location = _os.fspath(location)
721-
if not _path_isabs(location):
722-
try:
723-
location = _path_join(_os.getcwd(), location)
724-
except OSError:
725-
pass
726721

727722
# If the location is on the filesystem, but doesn't actually exist,
728723
# we could return None here, indicating that the location is not
@@ -1159,6 +1154,11 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics):
11591154

11601155
def __init__(self, name, path):
11611156
self.name = name
1157+
if not _path_isabs(path):
1158+
try:
1159+
path = _path_join(_os.getcwd(), path)
1160+
except OSError:
1161+
pass
11621162
self.path = path
11631163

11641164
def __eq__(self, other):

Lib/test/test_importlib/test_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,10 @@ def test_spec_from_file_location_relative_path(self):
815815

816816
self.assertEqual(spec.name, self.name)
817817
self.assertEqual(spec.loader, self.fileloader)
818-
self.assertEqual(spec.origin, self.path)
818+
self.assertEqual(spec.origin, os.path.basename(self.path))
819819
self.assertIs(spec.loader_state, None)
820820
self.assertIs(spec.submodule_search_locations, None)
821-
self.assertEqual(spec.cached, self.cached)
821+
self.assertEqual(spec.cached, os.path.relpath(self.cached))
822822
self.assertTrue(spec.has_location)
823823

824824
(Frozen_FactoryTests,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
No longer eagerly makes import filenames absolute, except for extension
2+
modules.

0 commit comments

Comments
 (0)