Gate BuiltinImporter and FrozenImporter load_module to Python < 3.15 - #16031
Gate BuiltinImporter and FrozenImporter load_module to Python < 3.15#16031raul-sq wants to merge 4 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
…/raul-sq/typeshed into fix-frozen-importlib-load-module
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
| @classmethod | ||
| @deprecated("Deprecated since Python 3.4; removed in Python 3.15. Use `exec_module()` instead.") | ||
| def load_module(cls, fullname: str) -> types.ModuleType: ... |
There was a problem hiding this comment.
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 ?
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.BuiltinImporterand_frozen_importlib.FrozenImporterbehind
sys.version_info < (3, 15)with a@deprecatedmessage, followingthe existing
find_modulepattern 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).