Skip to content

gh-133656: Remove deprecated zipimport.zipimporter.load_module #133662

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.

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Wulian233
Copy link
Contributor

@Wulian233 Wulian233 commented May 8, 2025

@sharktide
Copy link
Contributor

@Wulian233

considering how pyhton imports work, You might have to modify the files that run on import or any references to load_module. This will be a really daunting task for you :( sorry!

@sharktide
Copy link
Contributor

@Wulian233 Will review tmrw

Copy link
Contributor

@sharktide sharktide left a comment

Choose a reason for hiding this comment

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

This PR seems sound, however I'll approve it after stanfromireland and hugovk resolve their conversation, because I am not sure either if it should or shouldn't be in the devguide either :)

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

There is some additional sys.path manipulation added to the test case that doesn't look like it should be necessary.

Otherwise this looks good to me.

@@ -552,17 +551,12 @@ def testZipImporterMethods(self):
"spam" + pyc_ext: test_pyc}
self.makeZip(files, file_comment=b"spam")

sys.path.insert(0, TEMP_ZIP)
Copy link
Contributor

Choose a reason for hiding this comment

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

This addition to the test case doesn't seem like it should be necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

As per discussion, the addition is needed, but can be moved further down in the test case (before the first full import request)

@@ -671,15 +665,12 @@ def testZipImporterMethodsInSubDirectory(self):
packdir2 + TESTMOD + pyc_ext: test_pyc}
self.makeZip(files, file_comment=b"eggs")

sys.path.insert(0, TEMP_ZIP + os.sep + TESTPACK)
Copy link
Contributor

Choose a reason for hiding this comment

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

As above (this addition doesn't look correct)

Copy link
Contributor

@ncoghlan ncoghlan Aug 11, 2025

Choose a reason for hiding this comment

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

This can use the expected_path_path value from above, rather than recalculating it. (Never mind, that local is in a different test case method)

As per discussion, the addition is needed, but can be moved further down in the test case (before the first full import request)

@bedevere-app
Copy link

bedevere-app bot commented Aug 2, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@Wulian233
Copy link
Contributor Author

Wulian233 commented Aug 3, 2025

There is some additional sys.path manipulation added to the test case that doesn't look like it should be necessary.

Otherwise this looks good to me.

That's necessary. If these two lines are removed, the test will fail (p1)
2025-08-03 132623

with a ModuleNotFoundError because the modules cannot be found. If they are added back, the test passes. We need to make sure Python can find them, which maybe is the negative effect of removing load_module? I'm not an expert for this, and I don't know the underlying reasons for them, sorry

And sys.path.insert is also used in many other places in this file, for example:

https://github.com/Wulian233/cpython/blob/5616e27403799b481f44f96c3a21336fd03941c9/Lib/test/test_zipimport.py#L165
屏幕截图 2025-08-03 134313

https://github.com/Wulian233/cpython/blob/5616e27403799b481f44f96c3a21336fd03941c9/Lib/test/test_zipimport.py#L373

https://github.com/Wulian233/cpython/blob/5616e27403799b481f44f96c3a21336fd03941c9/Lib/test/test_zipimport.py#L420-L422
屏幕截图 2025-08-03 134236

@Wulian233 Wulian233 requested a review from ncoghlan August 11, 2025 02:03
@ncoghlan
Copy link
Contributor

@Wulian233 You're right, the importlib.import_module lines were previously only passing because the prior zi.load_module call had left sys.modules["TESTPACK"] populated.

Given that, it makes sense to keep the path manipulation additions, but move them as far down in their respective test cases as possible to still let the everything pass (which should be just before the importlib.import_module line in each case, since the direct instantiation shouldn't care if the zip archive is on sys.path or not, while importlib.import_module does care).

@Wulian233 Wulian233 requested a review from AA-Turner as a code owner August 11, 2025 13:16
@Wulian233
Copy link
Contributor Author

I have made the requested changes; please review again

thanks!

@bedevere-app
Copy link

bedevere-app bot commented Aug 11, 2025

Thanks for making the requested changes!

@ncoghlan: please review the changes made to this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants