GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-94379: Remove zipimport find_loader() and find_module() methods by vstinner · Pull Request #94380 · python/cpython

gh-94379: Remove zipimport find_loader() and find_module() methods #94380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
vstinner merged 1 commit into python:main from vstinner:zipimport
Jul 5, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

gh-94379: Remove zipimport find_loader() and find_module() methods #94380

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
9328dfe
gh-94379: Remove zipimport find_loader() and find_module() methods
vstinner Jun 28, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

5 changes: 5 additions & 0 deletions 5 Doc/whatsnew/3.12.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ Removed
has no ``copy()`` method, only a ``__copy__()`` method.
(Contributed by Victor Stinner in :gh:`94383`.)

* :mod:`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.
(Contributed by Victor Stinner in :gh:`94379`.)


Porting to Python 3.12
======================
Expand Down
16 changes: 0 additions & 16 deletions 16 Lib/test/test_zipimport.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,6 @@ def testZipImporterMethods(self):
# PEP 302
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
find_mod = zi.find_module('spam')
self.assertIsNotNone(find_mod)
self.assertIsInstance(find_mod, zipimport.zipimporter)
self.assertFalse(find_mod.is_package('spam'))
load_mod = find_mod.load_module('spam')
self.assertEqual(find_mod.get_filename('spam'), load_mod.__file__)

mod = zi.load_module(TESTPACK)
self.assertEqual(zi.get_filename(TESTPACK), mod.__file__)
Expand Down Expand Up @@ -586,16 +580,6 @@ def testZipImporterMethodsInSubDirectory(self):

pkg_path = TEMP_ZIP + os.sep + packdir + TESTPACK2
zi2 = zipimport.zipimporter(pkg_path)
# PEP 302
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
find_mod_dotted = zi2.find_module(TESTMOD)
self.assertIsNotNone(find_mod_dotted)
self.assertIsInstance(find_mod_dotted, zipimport.zipimporter)
self.assertFalse(zi2.is_package(TESTMOD))
load_mod = find_mod_dotted.load_module(TESTMOD)
self.assertEqual(
find_mod_dotted.get_filename(TESTMOD), load_mod.__file__)

# PEP 451
spec = zi2.find_spec(TESTMOD)
Expand Down
58 changes: 0 additions & 58 deletions 58 Lib/zipimport.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -102,64 +102,6 @@ def __init__(self, path):
self.prefix += path_sep


# Check whether we can satisfy the import of the module named by
# 'fullname', or whether it could be a portion of a namespace
# package. Return self if we can load it, a string containing the
# full path if it's a possible namespace portion, None if we
# can't load it.
def find_loader(self, fullname, path=None):
"""find_loader(fullname, path=None) -> self, str or None.

Search for a module specified by 'fullname'. 'fullname' must be the
fully qualified (dotted) module name. It returns the zipimporter
instance itself if the module was found, a string containing the
full path name if it's possibly a portion of a namespace package,
or None otherwise. The optional 'path' argument is ignored -- it's
there for compatibility with the importer protocol.

Deprecated since Python 3.10. Use find_spec() instead.
"""
_warnings.warn("zipimporter.find_loader() is deprecated and slated for "
"removal in Python 3.12; use find_spec() instead",
DeprecationWarning)
mi = _get_module_info(self, fullname)
if mi is not None:
# This is a module or package.
return self, []

# Not a module or regular package. See if this is a directory, and
# therefore possibly a portion of a namespace package.

# We're only interested in the last path component of fullname
# earlier components are recorded in self.prefix.
modpath = _get_module_path(self, fullname)
if _is_dir(self, modpath):
# This is possibly a portion of a namespace
# package. Return the string representing its path,
# without a trailing separator.
return None, [f'{self.archive}{path_sep}{modpath}']

return None, []


# Check whether we can satisfy the import of the module named by
# 'fullname'. Return self if we can, None if we can't.
def find_module(self, fullname, path=None):
"""find_module(fullname, path=None) -> self or None.

Search for a module specified by 'fullname'. 'fullname' must be the
fully qualified (dotted) module name. It returns the zipimporter
instance itself if the module was found, or None if it wasn't.
The optional 'path' argument is ignored -- it's there for compatibility
with the importer protocol.

Deprecated since Python 3.10. Use find_spec() instead.
"""
_warnings.warn("zipimporter.find_module() is deprecated and slated for "
"removal in Python 3.12; use find_spec() instead",
DeprecationWarning)
return self.find_loader(fullname, path)[0]

def find_spec(self, fullname, target=None):
"""Create a ModuleSpec for the specified module.

Expand Down
3 changes: 3 additions & 0 deletions 3 Misc/NEWS.d/next/Library/2022-06-28-14-29-21.gh-issue-94379.RrgKfh.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:mod:`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. Patch by Victor Stinner.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.