bpo-26131: Deprecate usage of load_module() (GH-23469)

Raise an ImportWarning when the import system falls back on load_module(). As for implementations of load_module(), raise a DeprecationWarning.
This commit is contained in:
Brett Cannon 2020-12-04 15:39:21 -08:00 committed by GitHub
parent 79c1849b9e
commit 2de5097ba4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 3245 additions and 3034 deletions

View file

@ -22,6 +22,7 @@ import _io # for open
import marshal # for loads
import sys # for modules
import time # for mktime
import _warnings # For warn()
__all__ = ['ZipImportError', 'zipimporter']
@ -268,8 +269,11 @@ class zipimporter(_bootstrap_external._LoaderBasics):
fully qualified (dotted) module name. It returns the imported
module, or raises ZipImportError if it wasn't found.
Deprecated since Python 3.10. use exec_module() instead.
Deprecated since Python 3.10. Use exec_module() instead.
"""
msg = ("zipimport.zipimporter.load_module() is deprecated and slated for "
"removal in Python 3.12; use exec_module() instead")
_warnings.warn(msg, DeprecationWarning)
code, ispackage, modpath = _get_module_code(self, fullname)
mod = sys.modules.get(fullname)
if mod is None or not isinstance(mod, _module_type):