Skip to content

Commit 1d5fa40

Browse files
committed
bpo-45272: os.path should not be a frozen module
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent 62bf263 commit 1d5fa40

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Lib/importlib/_bootstrap.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,13 @@ def _requires_builtin_wrapper(self, fullname):
263263
def _requires_frozen(fxn):
264264
"""Decorator to verify the named module is frozen."""
265265
def _requires_frozen_wrapper(self, fullname):
266-
if not _imp.is_frozen(fullname):
266+
if not _imp.is_frozen(fullname) or (
267+
# bpo-45272: os.path is not a concrete module, but an importable
268+
# attribute of 'os'. _imp.is_frozen('os.path') returns
269+
# False but it is frozen, so we check the loader here.
270+
fullname in sys.modules
271+
and sys.modules[fullname].__spec__.loader is FrozenImporter
272+
):
267273
raise ImportError('{!r} is not a frozen module'.format(fullname),
268274
name=fullname)
269275
return fxn(self, fullname)

Python/frozen.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ static const struct _frozen stdlib_modules[] = {
8484
{"genericpath", _Py_M__genericpath, (int)sizeof(_Py_M__genericpath)},
8585
{"ntpath", _Py_M__ntpath, (int)sizeof(_Py_M__ntpath)},
8686
{"posixpath", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath)},
87-
{"os.path", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath)},
8887
{"os", _Py_M__os, (int)sizeof(_Py_M__os)},
8988
{"site", _Py_M__site, (int)sizeof(_Py_M__site)},
9089
{"stat", _Py_M__stat, (int)sizeof(_Py_M__stat)},
@@ -114,7 +113,6 @@ const struct _frozen *_PyImport_FrozenTest = test_modules;
114113
static const struct _module_alias aliases[] = {
115114
{"_frozen_importlib", "importlib._bootstrap"},
116115
{"_frozen_importlib_external", "importlib._bootstrap_external"},
117-
{"os.path", "posixpath"},
118116
{"__hello_alias__", "__hello__"},
119117
{"__phello_alias__", "__hello__"},
120118
{"__phello_alias__.spam", "__hello__"},

Tools/scripts/freeze_modules.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ def find_tool():
8888
'genericpath',
8989
'ntpath',
9090
'posixpath',
91-
# We must explicitly mark os.path as a frozen module
92-
# even though it will never be imported.
93-
f'{OS_PATH} : os.path',
9491
'os',
9592
'site',
9693
'stat',

0 commit comments

Comments
 (0)