Skip to content
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

gh-125746: Delay deprecated zipimport.zipimporter.load_module removal time to 3.15 #125748

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

Conversation

Wulian233
Copy link
Contributor

@Wulian233 Wulian233 commented Oct 20, 2024

#125746 (comment)

I would like to hold off on this change for one more version. A quick GitHub search shows that 1.8k projects are still relying on load_module (and my regular expression isn't perfect, so I'm certain that we're missing some).

The new zipimport methods (I'm using "new" loosely here, I'm talking about the 3.10 methods) were only added to typeshed in late June, so I would assume that many were intentionally using load_module over exec_module, because their IDE was telling them that it doesn't exist (to confirm that, adjusting my GitHub search shows that only 250 projects are using exec_module). Similarly, load_module isn't marked as @deprecated on typeshed, so when we did add it, it's unlikely that people realized they needed to migrate.


📚 Documentation preview 📚: https://cpython-previews--125748.org.readthedocs.build/

@rruuaanng
Copy link
Contributor

I also encountered this problem, but I don't know why it happened. I opened an issue.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

I would like to postpone this until 3.15. Please update the PR to move the load_module deprecation to pending-removal-in-3.15

@Wulian233 Wulian233 changed the title gh-125746: Remove deprecated zipimport.zipimporter.load_module gh-125746: Delay deprecated zipimport.zipimporter.load_module removal time to 3.15 Oct 20, 2024
@Wulian233
Copy link
Contributor Author

You're right, when I did this pr, my vscode (the latest Python extension) didn't prompt exec_module either. I will edit the pending-removal-in-3.15.rst and Lib/zipimport.py to remove the entries for pending-removal-in-future.rst

@Wulian233 Wulian233 reopened this Oct 21, 2024
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Thank you! LGTM.

Lib/zipimport.py Outdated
@@ -222,7 +222,7 @@ def load_module(self, fullname):
Deprecated since Python 3.10. Use exec_module() instead.
"""
msg = ("zipimport.zipimporter.load_module() is deprecated and slated for "
"removal in Python 3.12; use exec_module() instead")
"removal in Python 3.15; use exec_module() instead")
Copy link
Member

Choose a reason for hiding this comment

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

We should probably update this to use warnings._deprecated().

cpython/Lib/warnings.py

Lines 650 to 668 in 5b7a872

_DEPRECATED_MSG = "{name!r} is deprecated and slated for removal in Python {remove}"
def _deprecated(name, message=_DEPRECATED_MSG, *, remove, _version=sys.version_info):
"""Warn that *name* is deprecated or should be removed.
RuntimeError is raised if *remove* specifies a major/minor tuple older than
the current Python version or the same version but past the alpha.
The *message* argument is formatted with *name* and *remove* as a Python
version tuple (e.g. (3, 11)).
"""
remove_formatted = f"{remove[0]}.{remove[1]}"
if (_version[:2] > remove) or (_version[:2] == remove and _version[3] != "alpha"):
msg = f"{name!r} was slated for removal after Python {remove_formatted} alpha"
raise RuntimeError(msg)
else:
msg = message.format(name=name, remove=remove_formatted)
warn(msg, DeprecationWarning, stacklevel=3)

@bedevere-app
Copy link

bedevere-app bot commented Oct 21, 2024

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 Oct 21, 2024

test_cmd_line_script test failed but I don't know why.

It appears that there is no relevant code here, only the use of the zipimport.zipimporter

@bedevere-app
Copy link

bedevere-app bot commented Oct 21, 2024

Thanks for making the requested changes!

@brettcannon: 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.

4 participants