Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 378211f

Browse files
authored
bpo-44070: No longer eagerly makes import filenames absolute, except for extension modules (GH-26025) (#26028)
1 parent 8a12f46 commit 378211f

File tree

4 files changed

+1845
-1843
lines changed

4 files changed

+1845
-1843
lines changed

Lib/importlib/_bootstrap_external.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,6 @@ def spec_from_file_location(name, location=None, *, loader=None,
711711
pass
712712
else:
713713
location = _os.fspath(location)
714-
if not _path_isabs(location):
715-
try:
716-
location = _path_join(_os.getcwd(), location)
717-
except OSError:
718-
pass
719714

720715
# If the location is on the filesystem, but doesn't actually exist,
721716
# we could return None here, indicating that the location is not
@@ -1152,6 +1147,11 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics):
11521147

11531148
def __init__(self, name, path):
11541149
self.name = name
1150+
if not _path_isabs(path):
1151+
try:
1152+
path = _path_join(_os.getcwd(), path)
1153+
except OSError:
1154+
pass
11551155
self.path = path
11561156

11571157
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, which was introduced in 3.8.10.

0 commit comments

Comments
 (0)