Skip to content

Commit 0cf02d7

Browse files
committed
Remove deprecated zipimport.zipimporter.load_module
1 parent e924bb6 commit 0cf02d7

File tree

6 files changed

+11
-77
lines changed

6 files changed

+11
-77
lines changed

Doc/deprecations/pending-removal-in-future.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,3 @@ although there is currently no date scheduled for their removal.
155155
:class:`~xml.etree.ElementTree.Element` is deprecated. In a future release it
156156
will always return ``True``. Prefer explicit ``len(elem)`` or
157157
``elem is not None`` tests instead.
158-
159-
* :meth:`zipimport.zipimporter.load_module` is deprecated:
160-
use :meth:`~zipimport.zipimporter.exec_module` instead.

Doc/library/zipimport.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,6 @@ zipimporter Objects
142142
:exc:`ZipImportError` if the module couldn't be found.
143143

144144

145-
.. method:: load_module(fullname)
146-
147-
Load the module specified by *fullname*. *fullname* must be the fully
148-
qualified (dotted) module name. Returns the imported module on success,
149-
raises :exc:`ZipImportError` on failure.
150-
151-
.. deprecated:: 3.10
152-
153-
Use :meth:`exec_module` instead.
154-
155-
156145
.. method:: invalidate_caches()
157146

158147
Clear out the internal cache of information about files found within

Doc/whatsnew/3.14.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,14 @@ urllib
612612
It had previously raised a :exc:`DeprecationWarning` since Python 3.11.
613613
(Contributed by Nikita Sobolev in :gh:`118827`.)
614614

615+
zipimport
616+
------
617+
618+
* Remove deprecated :meth:`!zipimport.zipimporter.load_module`. It had
619+
previously raised a :exc:`DeprecationWarning` since Python 3.10.
620+
Use :meth:`~zipimport.zipimporter.exec_module` instead.
621+
(Contributed by Jiahao Li in :gh:`125746`.)
622+
615623
Others
616624
------
617625

Lib/test/test_zipimport.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,6 @@ def testZipImporterMethods(self):
556556
self.assertEqual(zi.archive, TEMP_ZIP)
557557
self.assertTrue(zi.is_package(TESTPACK))
558558

559-
# PEP 302
560-
with warnings.catch_warnings():
561-
warnings.simplefilter("ignore", DeprecationWarning)
562-
563-
mod = zi.load_module(TESTPACK)
564-
self.assertEqual(zi.get_filename(TESTPACK), mod.__file__)
565-
566559
# PEP 451
567560
spec = zi.find_spec('spam')
568561
self.assertIsNotNone(spec)
@@ -675,11 +668,6 @@ def testZipImporterMethodsInSubDirectory(self):
675668
self.assertEqual(zi.archive, TEMP_ZIP)
676669
self.assertEqual(zi.prefix, packdir)
677670
self.assertTrue(zi.is_package(TESTPACK2))
678-
# PEP 302
679-
with warnings.catch_warnings():
680-
warnings.simplefilter("ignore", DeprecationWarning)
681-
mod = zi.load_module(TESTPACK2)
682-
self.assertEqual(zi.get_filename(TESTPACK2), mod.__file__)
683671
# PEP 451
684672
spec = zi.find_spec(TESTPACK2)
685673
mod = importlib.util.module_from_spec(spec)
@@ -1069,9 +1057,6 @@ def _testBogusZipFile(self):
10691057
z = zipimport.zipimporter(TESTMOD)
10701058

10711059
try:
1072-
with warnings.catch_warnings():
1073-
warnings.simplefilter("ignore", DeprecationWarning)
1074-
self.assertRaises(TypeError, z.load_module, None)
10751060
self.assertRaises(TypeError, z.find_module, None)
10761061
self.assertRaises(TypeError, z.find_spec, None)
10771062
self.assertRaises(TypeError, z.exec_module, None)
@@ -1083,9 +1068,6 @@ def _testBogusZipFile(self):
10831068
error = zipimport.ZipImportError
10841069
self.assertIsNone(z.find_spec('abc'))
10851070

1086-
with warnings.catch_warnings():
1087-
warnings.simplefilter("ignore", DeprecationWarning)
1088-
self.assertRaises(error, z.load_module, 'abc')
10891071
self.assertRaises(error, z.get_code, 'abc')
10901072
self.assertRaises(OSError, z.get_data, 'abc')
10911073
self.assertRaises(error, z.get_source, 'abc')

Lib/zipimport.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import marshal # for loads
2121
import sys # for modules
2222
import time # for mktime
23-
import _warnings # For warn()
2423

2524
__all__ = ['ZipImportError', 'zipimporter']
2625

@@ -211,50 +210,6 @@ def is_package(self, fullname):
211210
return mi
212211

213212

214-
# Load and return the module named by 'fullname'.
215-
def load_module(self, fullname):
216-
"""load_module(fullname) -> module.
217-
218-
Load the module specified by 'fullname'. 'fullname' must be the
219-
fully qualified (dotted) module name. It returns the imported
220-
module, or raises ZipImportError if it could not be imported.
221-
222-
Deprecated since Python 3.10. Use exec_module() instead.
223-
"""
224-
msg = ("zipimport.zipimporter.load_module() is deprecated and slated for "
225-
"removal in Python 3.12; use exec_module() instead")
226-
_warnings.warn(msg, DeprecationWarning)
227-
code, ispackage, modpath = _get_module_code(self, fullname)
228-
mod = sys.modules.get(fullname)
229-
if mod is None or not isinstance(mod, _module_type):
230-
mod = _module_type(fullname)
231-
sys.modules[fullname] = mod
232-
mod.__loader__ = self
233-
234-
try:
235-
if ispackage:
236-
# add __path__ to the module *before* the code gets
237-
# executed
238-
path = _get_module_path(self, fullname)
239-
fullpath = _bootstrap_external._path_join(self.archive, path)
240-
mod.__path__ = [fullpath]
241-
242-
if not hasattr(mod, '__builtins__'):
243-
mod.__builtins__ = __builtins__
244-
_bootstrap_external._fix_up_module(mod.__dict__, fullname, modpath)
245-
exec(code, mod.__dict__)
246-
except:
247-
del sys.modules[fullname]
248-
raise
249-
250-
try:
251-
mod = sys.modules[fullname]
252-
except KeyError:
253-
raise ImportError(f'Loaded module {fullname!r} not found in sys.modules')
254-
_bootstrap._verbose_message('import {} # loaded from Zip {}', fullname, modpath)
255-
return mod
256-
257-
258213
def get_resource_reader(self, fullname):
259214
"""Return the ResourceReader for a module in a zip file."""
260215
from importlib.readers import ZipReader
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove deprecated :meth:`!zipimport.zipimporter.load_module`. It had
2+
previously raised a :exc:`DeprecationWarning` since Python 3.10. Use
3+
:meth:`~zipimport.zipimporter.exec_module` instead.

0 commit comments

Comments
 (0)