Skip to content

Gate BuiltinImporter and FrozenImporter load_module to Python < 3.15#16031

Open
raul-sq wants to merge 4 commits into
python:mainfrom
raul-sq:fix-frozen-importlib-load-module
Open

Gate BuiltinImporter and FrozenImporter load_module to Python < 3.15#16031
raul-sq wants to merge 4 commits into
python:mainfrom
raul-sq:fix-frozen-importlib-load-module

Conversation

@raul-sq

@raul-sq raul-sq commented Jul 19, 2026

Copy link
Copy Markdown

load_module() was removed in Python 3.15 (deprecated since Python 3.4;
see the 3.15 What's New / importlib docs). This gates the declarations on
_frozen_importlib.BuiltinImporter and _frozen_importlib.FrozenImporter
behind sys.version_info < (3, 15) with a @deprecated message, following
the existing find_module pattern in the same file.

Addresses two TODO entries in stdlib/@tests/stubtest_allowlists/py315.txt
(entries intentionally left in place for now; will remove in a follow-up
commit once CI confirms).

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines +66 to +68
@classmethod
@deprecated("Deprecated since Python 3.4; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(cls, fullname: str) -> types.ModuleType: ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting -- there's no deprecation warning at runtime:

% uvx python3.14
Python 3.14.5 (main, May 10 2026, 19:20:57) [Clang 22.1.3 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from _frozen_importlib import *
>>> BuiltinImporter.load_module('abc')
<module 'abc' (built-in)>
>>> FrozenImporter.load_module('abc')
<module 'abc' (frozen)>
>>> FrozenImporter.load_module('shutil')

but I do see the general deprecation notice at https://docs.python.org/3.12/deprecations/index.html#pending-removal-in-python-3-15, so I think this is an appropriate use of @deprecated.

I feel like your existing comment doesn't add that much over what you can see in the code. Maybe get rid of it and replace it with a note that all load_module methods in importlib were deprecated, and link to https://docs.python.org/3.12/deprecations/index.html#pending-removal-in-python-3-15 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants