-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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-121604: Raise DeprecationWarnings in importlib #121765
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I left you some comments ;)
@@ -1,5 +1,5 @@ | |||
"""The machinery of importlib: finders, loaders, hooks, etc.""" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep the newline
Co-authored-by: Tomas R <tomas.roun8@gmail.com>
Thanks for the review Co-authored-by: Tomas R <tomas.roun8@gmail.com>
@tomasr8 thanks for the review, I made some changes. |
def __init__(self): | ||
warnings.warn(f"Loader is deprecated.", | ||
DeprecationWarning, stacklevel=2) | ||
super().__init__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure but I think we should raise the deprecation warning when the class is imported, not when you create a new instance with it. Going by the example in the original PEP 562 it'd look (I think) something like this:
# Rename the deprecated class
class _Loader(metaclass=abc.ABCMeta):
...
def __getattr__(name):
if name == 'Loader':
warnings.warn(f"The 'Loader' class is deprecated.",
DeprecationWarning, stacklevel=2)
return _Loader
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, no problem. Thanks for the reference link! Another approach I had was to just put the warning message by itself in the first line under the class name. Would this have a similar affect? I removed it because I then saw the deprecation error when running the make
command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem with the other approach is that you'll get the warning whenever you import the module, not just the deprecated class specifically. For example, import importlib.abc
will produce a warning for InspectLoader
even if you're not actually using it
|
||
|
||
def __getattr__(name): | ||
if name in ('DEBUG_BYTECODE_SUFFIXES', 'OPTIMIZED_BYTECODE_SUFFIXES', 'WindowsRegistryFinder'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first if
statement could be omitted, just use the if-elif
statement ;)
if name in ('DEBUG_BYTECODE_SUFFIXES', 'OPTIMIZED_BYTECODE_SUFFIXES'):
...
elif name == 'WindowsRegistryFinder':
...
Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
FYI this PR breaks the test suite, so CI isn't passing. |
Hi @rashansmith! Looks like this PR hasn't had any activity in a while, would you like to continue working on it? |
Hello @rashansmith if you do not have the time to complete this I can take on the project. |
Hey! Thanks for volunteering @StanFromIreland, but I'm already working on finishing this PR :/ If you still want to help with this though, I'd appreciate your review! I'll send the updated PR tomorrow 🙂 |
This MR is currently adding deprecation warnings to |
Hello everyone, thanks for taking this on. It was my first attempt at a PR in this repo so I'm looking forward to seeing how the work here is done and hopefully I can contribute to more work in the future! |
Thanks @rashansmith for your work! I'm giving you credit in the followup PR :) I'll close this now since it's superseded by #128007 |
This fixes #121604.
The others defined in the issue can be considered already done.
Issue: #121604
DeprecationWarning
#121604