← 返回首页
gh-94379: Remove zipimport find_loader() and find_module() methods by vstinner · Pull Request #94380 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

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

gh-94379: Remove zipimport find_loader() and find_module() methods#94380
vstinner merged 1 commit into
python:mainfrom
vstinner:zipimport

Conversation

vstinner commented Jun 28, 2022
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

cc @brettcannon

vstinner marked this pull request as ready for review June 28, 2022 14:08

brettcannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

The code removal looks fine, but the doc changes left out the removal of load_module() as well.

Comment thread Lib/zipimport.py Outdated Show resolved Hide resolved

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Copy link
Copy Markdown
Member Author

@brettcannon: I updated the PR to mention also load_module() removal, and fix test_zipimport... But now, I feel that I removed too many lines in the tests! Maybe the tests should be fixed instead?

Problem: I don't know how to fix the packdir2 tests:

mod_path = packdir2 + TESTMOD mod_name = module_path_to_dotted_name(mod_path) - mod = importlib.import_module(mod_name) - self.assertTrue(mod_name in sys.modules) - self.assertIsNone(zi.get_source(TESTPACK)) - self.assertIsNone(zi.get_source(mod_path)) - self.assertEqual(zi.get_filename(mod_path), mod.__file__) - # To pass in the module name instead of the path, we must use the - # right importer - loader = mod.__spec__.loader - self.assertIsNone(loader.get_source(mod_name)) - self.assertEqual(loader.get_filename(mod_name), mod.__file__)

Comment thread Doc/whatsnew/3.12.rst Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

find_spec() only replaces find_loader() and find_module(), so this sentence is a bit misleading. Same is true for the news entry.

Comment thread Lib/test/test_zipimport.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Why the test removals for lines that don't directly use the associated methods?

Copy link
Copy Markdown
Member

I don't know how to fix the packdir2 test

How is it failing?

Maybe only do the find_*() methods in this PR and worry about load_module() in another one?

vstinner commented Jul 4, 2022

Copy link
Copy Markdown
Member Author

Maybe only do the find_*() methods in this PR and worry about load_module() in another one?

Good idea! I modified this PR to only remove find_loader() and find_module() methods: keep load_module() for now (it can be removed in a separated PR).

vstinner commented Jul 4, 2022

Copy link
Copy Markdown
Member Author

@brettcannon: Would you mind to review the updated PR? Now it only removes find_loader() and find_module() methods, and it only removes the bare minimum lines in test_zipimport.py.

Once the PR gets approved, I will solve the Doc/whatsnew/3.12.rst conflict.

Copy link
Copy Markdown
Member

@vstinner LGTM! And an FYI for anyone else who reviews, the get_filename() function gets used in other places, so it still gets tested.

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.
vstinner merged commit 92bcb26 into python:main Jul 5, 2022
vstinner deleted the zipimport branch July 5, 2022 10:11

vstinner commented Jul 5, 2022

Copy link
Copy Markdown
Member Author

Thanks for the reviews @warsaw and @brettcannon! It's easier to modify zipimport since @serhiy-storchaka rewrote it in pure Python :-)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Footer

© 2026 GitHub, Inc.