Skip to content

Commit 7a33c7a

Browse files
committed
Remove deprecated zipimport.zipimporter.load_module
1 parent 8bb9286 commit 7a33c7a

File tree

7 files changed

+9
-86
lines changed

7 files changed

+9
-86
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,3 @@ Pending removal in Python 3.15
9696
and :meth:`~wave.Wave_read.getmarkers` methods of
9797
the :class:`~wave.Wave_read` and :class:`~wave.Wave_write` classes
9898
have been deprecated since Python 3.13.
99-
100-
* :mod:`zipimport`:
101-
102-
* :meth:`~zipimport.zipimporter.load_module` has been deprecated since
103-
Python 3.10. Use :meth:`~zipimport.zipimporter.exec_module` instead.
104-
(Contributed by Jiahao Li in :gh:`125746`.)

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-removed:: 3.10 3.15
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.15.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ Deprecated
115115
Removed
116116
=======
117117

118-
module_name
119-
-----------
118+
zipimport
119+
---------
120120

121-
* TODO
121+
* Remove deprecated :meth:`!zipimport.zipimporter.load_module`.
122+
They had previously raised a :exc:`DeprecationWarning` since Python 3.10.
123+
Use :meth:`zipimport.zipimporter.exec_module` instead.
124+
(Contributed by Jiahao Li in :gh:`133656`.)
122125

123126

124127
Porting to Python 3.15

Lib/test/test_zipimport.py

Lines changed: 0 additions & 19 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)
@@ -1082,10 +1067,6 @@ def _testBogusZipFile(self):
10821067

10831068
error = zipimport.ZipImportError
10841069
self.assertIsNone(z.find_spec('abc'))
1085-
1086-
with warnings.catch_warnings():
1087-
warnings.simplefilter("ignore", DeprecationWarning)
1088-
self.assertRaises(error, z.load_module, 'abc')
10891070
self.assertRaises(error, z.get_code, 'abc')
10901071
self.assertRaises(OSError, z.get_data, 'abc')
10911072
self.assertRaises(error, z.get_source, 'abc')

Lib/zipimport.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -210,52 +210,6 @@ def is_package(self, fullname):
210210
return mi
211211

212212

213-
# Load and return the module named by 'fullname'.
214-
def load_module(self, fullname):
215-
"""load_module(fullname) -> module.
216-
217-
Load the module specified by 'fullname'. 'fullname' must be the
218-
fully qualified (dotted) module name. It returns the imported
219-
module, or raises ZipImportError if it could not be imported.
220-
221-
Deprecated since Python 3.10. Use exec_module() instead.
222-
"""
223-
import warnings
224-
warnings._deprecated("zipimport.zipimporter.load_module",
225-
f"{warnings._DEPRECATED_MSG}; "
226-
"use zipimport.zipimporter.exec_module() instead",
227-
remove=(3, 15))
228-
code, ispackage, modpath = _get_module_code(self, fullname)
229-
mod = sys.modules.get(fullname)
230-
if mod is None or not isinstance(mod, _module_type):
231-
mod = _module_type(fullname)
232-
sys.modules[fullname] = mod
233-
mod.__loader__ = self
234-
235-
try:
236-
if ispackage:
237-
# add __path__ to the module *before* the code gets
238-
# executed
239-
path = _get_module_path(self, fullname)
240-
fullpath = _bootstrap_external._path_join(self.archive, path)
241-
mod.__path__ = [fullpath]
242-
243-
if not hasattr(mod, '__builtins__'):
244-
mod.__builtins__ = __builtins__
245-
_bootstrap_external._fix_up_module(mod.__dict__, fullname, modpath)
246-
exec(code, mod.__dict__)
247-
except:
248-
del sys.modules[fullname]
249-
raise
250-
251-
try:
252-
mod = sys.modules[fullname]
253-
except KeyError:
254-
raise ImportError(f'Loaded module {fullname!r} not found in sys.modules')
255-
_bootstrap._verbose_message('import {} # loaded from Zip {}', fullname, modpath)
256-
return mod
257-
258-
259213
def get_resource_reader(self, fullname):
260214
"""Return the ResourceReader for a module in a zip file."""
261215
from importlib.readers import ZipReader

Misc/NEWS.d/3.14.0a6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ Patch by Semyon Moroz.
758758
.. nonce: wDLTay
759759
.. section: Library
760760
761-
Delay deprecated :meth:`zipimport.zipimporter.load_module` removal time to
761+
Delay deprecated :meth:`!zipimport.zipimporter.load_module` removal time to
762762
3.15. Use :meth:`zipimport.zipimporter.exec_module` instead.
763763

764764
..
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove deprecated :meth:`!zipimport.zipimporter.load_module`. Use
2+
:meth:`zipimport.zipimporter.exec_module` instead.

0 commit comments

Comments
 (0)