8000 gh-94379: Remove zipimport find_loader() and find_module() methods (#… · python/cpython@92bcb26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 92bcb26

Browse files
authored
gh-94379: Remove zipimport find_loader() and find_module() methods (#94380)
zipimport: Remove find_loader() and find_module() methods, deprecated in Python 3.10: use the find_spec() method instead. See PEP 451 for the rationale.
1 parent 3440d19 commit 92bcb26

File tree

4 files changed

+8
-74
lines changed

4 files changed

+8
-74
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ Removed
299299
has no ``copy()`` method, only a ``__copy__()`` method.
300300
(Contributed by Victor Stinner in :gh:`94383`.)
301301

302+
* :mod:`zipimport`: Remove ``find_loader()`` and ``find_module()`` methods,
303+
deprecated in Python 3.10: use the ``find_spec()`` method instead. See
304+
:pep:`451` for the rationale.
305+
(Contributed by Victor Stinner in :gh:`94379`.)
306+
302307

303308
Porting to Python 3.12
304309
======================

Lib/test/test_zipimport.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,6 @@ def testZipImporterMethods(self):
460460
# PEP 302
461461
with warnings.catch_warnings():
462462
warnings.simplefilter("ignore", DeprecationWarning)
463-
find_mod = zi.find_module('spam')
464-
self.assertIsNotNone(find_mod)
465-
self.assertIsInstance(find_mod, zipimport.zipimporter)
466-
self.assertFalse(find_mod.is_package('spam'))
467-
load_mod = find_mod.load_module('spam')
468-
self.assertEqual(find_mod.get_filename('spam'), load_mod.__file__)
469463

470464
mod = zi.load_module(TESTPACK)
471465
self.assertEqual(zi.get_filename(TESTPACK), mod.__file__)
@@ -586,16 +580,6 @@ def testZipImporterMethodsInSubDirectory(self):
586580

587581
pkg_path = TEMP_ZIP + os.sep + packdir + TESTPACK2
588582
zi2 = zipimport.zipimporter(pkg_path)
589-
# PEP 302
590-
with warnings.catch_warnings():
591-
warnings.simplefilter("ignore", DeprecationWarning)
592-
find_mod_dotted = zi2.find_module(TESTMOD)
593-
self.assertIsNotNone(find_mod_dotted)
594-
self.assertIsInstance(find_mod_dotted, zipimport.zipimporter)
595-
self.assertFalse(zi2.is_package(TESTMOD))
596-
load_mod = find_mod_dotted.load_module(TESTMOD)
597-
self.assertEqual(
598-
find_mod_dotted.get_filename(TESTMOD), load_mod.__file__)
599583

600584
# PEP 451
601585
spec = zi2.find_spec(TESTMOD)

Lib/zipimport.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -102,64 +102,6 @@ def __init__(self, path):
102102
self.prefix += path_sep
103103

104104

105-
# Check whether we can satisfy the import of the module named by
106-
# 'fullname', or whether it could be a portion of a namespace
107-
# package. Return self if we can load it, a string containing the
108-
# full path if it's a possible namespace portion, None if we
109-
# can't load it.
110-
def find_loader(self, fullname, path=None):
111-
"""find_loader(fullname, path=None) -> self, str or None.
112-
113-
Search for a module specified by 'fullname'. 'fullname' must be the
114-
fully qualified (dotted) module name. It returns the zipimporter
115-
instance itself if the module was found, a string containing the
116-
full path name if it's possibly a portion of a namespace package,
117-
or None otherwise. The optional 'path' argument is ignored -- it's
118-
there for compatibility with the importer protocol.
119-
120-
Deprecated since Python 3.10. Use find_spec() instead.
121-
"""
122-
_warnings.warn("zipimporter.find_loader() is deprecated and slated for "
123-
"removal in Python 3.12; use find_spec() instead",
124-
DeprecationWarning)
125-
mi = _get_module_info(self, fullname)
126-
if mi is not None:
127-
# This is a module or package.
128-
return self, []
129-
130-
# Not a module or regular package. See if this is a directory, and
131-
# therefore possibly a portion of a namespace package.
132-
133-
# We're only interested in the last path component of fullname
134-
# earlier components are recorded in self.prefix.
135-
modpath = _get_module_path(self, fullname)
136-
if _is_dir(self, modpath):
137-
# This is possibly a portion of a namespace
138-
# package. Return the string representing its path,
139-
# without a trailing separator.
140-
return None, [f'{self.archive}{path_sep}{modpath}']
141-
142-
return None, []
143-
144-
145-
# Check whether we can satisfy the import of the module named by
146-
# 'fullname'. Return self if we can, None if we can't.
147-
def find_module(self, fullname, path=None):
148-
"""find_module(fullname, path=None) -> self or None.
149-
150-
Search for a module specified by 'fullname'. 'fullname' must be the
151-
fully qualified (dotted) module name. It returns the zipimporter
152-
instance itself if the module was found, or None if it wasn't.
153-
The optional 'path' argument is ignored -- it's there for compatibility
154-
with the importer protocol.
155-
156-
Deprecated since Python 3.10. Use find_spec() instead.
157-
"""
158-
_warnings.warn("zipimporter.find_module() is deprecated and slated for "
159-
"removal in Python 3.12; use find_spec() instead",
160-
DeprecationWarning)
161-
return self.find_loader(fullname, path)[0]
162-
163105
def find_spec(self, fullname, target=None):
164106
"""Create a ModuleSpec for the specified module.
165107
Lines changed: 3 additions & 0 deletions
+
deprecated in Python 3.10: use the ``find_spec()`` method instead. See
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`zipimport`: Remove ``find_loader()`` and ``find_module()`` methods,
2
3+
:pep:`451` for the rationale. Patch by Victor Stinner.

0 commit comments

Comments
 (0)
0