diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index afb95f4e1df869..7c8032f0d1e2a6 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -263,7 +263,13 @@ def _requires_builtin_wrapper(self, fullname): def _requires_frozen(fxn): """Decorator to verify the named module is frozen.""" def _requires_frozen_wrapper(self, fullname): - if not _imp.is_frozen(fullname): + if not _imp.is_frozen(fullname) or ( + # bpo-45272: os.path is not a concrete module, but an importable + # attribute of 'os'. _imp.is_frozen('os.path') returns + # False but it is frozen, so we check the loader here. + fullname in sys.modules + and sys.modules[fullname].__spec__.loader is FrozenImporter + ): raise ImportError('{!r} is not a frozen module'.format(fullname), name=fullname) return fxn(self, fullname) diff --git a/Python/frozen.c b/Python/frozen.c index 15baa97b9d0553..0f7890d8e3106a 100644 --- a/Python/frozen.c +++ b/Python/frozen.c @@ -84,7 +84,6 @@ static const struct _frozen stdlib_modules[] = { {"genericpath", _Py_M__genericpath, (int)sizeof(_Py_M__genericpath)}, {"ntpath", _Py_M__ntpath, (int)sizeof(_Py_M__ntpath)}, {"posixpath", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath)}, - {"os.path", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath)}, {"os", _Py_M__os, (int)sizeof(_Py_M__os)}, {"site", _Py_M__site, (int)sizeof(_Py_M__site)}, {"stat", _Py_M__stat, (int)sizeof(_Py_M__stat)}, @@ -114,7 +113,6 @@ const struct _frozen *_PyImport_FrozenTest = test_modules; static const struct _module_alias aliases[] = { {"_frozen_importlib", "importlib._bootstrap"}, {"_frozen_importlib_external", "importlib._bootstrap_external"}, - {"os.path", "posixpath"}, {"__hello_alias__", "__hello__"}, {"__phello_alias__", "__hello__"}, {"__phello_alias__.spam", "__hello__"}, diff --git a/Tools/scripts/freeze_modules.py b/Tools/scripts/freeze_modules.py index 36142625ca6090..4f7eb04ea5ed42 100644 --- a/Tools/scripts/freeze_modules.py +++ b/Tools/scripts/freeze_modules.py @@ -88,9 +88,6 @@ def find_tool(): 'genericpath', 'ntpath', 'posixpath', - # We must explicitly mark os.path as a frozen module - # even though it will never be imported. - f'{OS_PATH} : os.path', 'os', 'site', 'stat',