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

Make sure all deprecated items in importlib raise DeprecationWarning #121604

Open
7 of 11 tasks
brettcannon opened this issue Jul 10, 2024 · 10 comments
Open
7 of 11 tasks

Make sure all deprecated items in importlib raise DeprecationWarning #121604

brettcannon opened this issue Jul 10, 2024 · 10 comments
Assignees
Labels
3.14 new features, bugs and security fixes easy topic-importlib

Comments

@brettcannon brettcannon added topic-importlib 3.14 new features, bugs and security fixes labels Jul 10, 2024
@brettcannon brettcannon changed the title Make sure all deprecated items inimportlib Make sure all deprecated items in importlib raise DeprecationWarning Jul 10, 2024
@encukou encukou added the easy label Jul 13, 2024
@rashansmith
Copy link
Contributor

rashansmith commented Jul 13, 2024

I will try this one at europython :)

@tomasr8
Copy link
Member

tomasr8 commented Jul 13, 2024

@rashansmith

To add deprecation warnings to module-level constants like DEBUG_BYTECODE_SUFFIXES I think you can use something like this:

cpython/Lib/calendar.py

Lines 44 to 54 in 4e36dd7

def __getattr__(name):
if name in ('January', 'February'):
import warnings
warnings.warn(f"The '{name}' attribute is deprecated, use '{name.upper()}' instead",
DeprecationWarning, stacklevel=2)
if name == 'January':
return 1
else:
return 2
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

@rashansmith
Copy link
Contributor

@tomasr8 thanks, I've been looking at this exact file as a reference! Can you confirm which of the tasks are already done? For example in _abc.py, in the load_module() function I can already see a "# Warning implemented in _load_module_shim()." message.

@willingc
Copy link
Contributor

Hi @brettcannon, I'm sitting at Europython sprints and working with @rashansmith. If you know if any of these have already been done, please let us know. Going to check the history :D

@bedevere-app
Copy link

bedevere-app bot commented Jul 14, 2024

GH-121765 is a backport of this pull request to the 3.14 branch.

@rashansmith
Copy link
Contributor

@brettcannon @willingc @tomasr8 I've created a PR for this issue. Please let me know if it looks good or any issues I should resolve. It is based on validating which deprecationwarnings have already been implemented from the list, and therefore working on the remainders:

@brettcannon
Copy link
Member Author

@willingc @rashansmith I made the list from the docs based on a comment on another issue that made it sound like SourceFileLoader.load_module() wasn't raising an exception. I had not taken the time to verify anything. So thanks to @rashansmith for checking! I'll update the list based on what you found.

@brettcannon brettcannon self-assigned this Sep 26, 2024
@tungol
Copy link
Contributor

tungol commented Dec 16, 2024

Do we have it documented somewhere that importlib.abc.Loader is deprecated? The current importlib docs only say that importlib.abc.Loader.load_module is deprecated.

@tomasr8
Copy link
Member

tomasr8 commented Dec 16, 2024

I don't think it is. At least there are no deprecation warnings in the code, just for load_module.

@tungol
Copy link
Contributor

tungol commented Dec 16, 2024

That's what I thought, but I was thinking maybe I missed something given the warnings that the linked MR is adding. I'll bring the conversation over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 new features, bugs and security fixes easy topic-importlib
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants