Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-121604: Raise DeprecationWarnings in importlib#121765
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
03bbac0820ac21d6c0645cf8264dcfbe0796294458f2458cbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| """The machinery of importlib: finders, loaders, hooks, etc.""" | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd keep the newline | ||
| import warnings | ||
| from ._bootstrap import ModuleSpec | ||
| from ._bootstrap import BuiltinImporter | ||
| from ._bootstrap import FrozenImporter | ||
| @@ -27,3 +28,15 @@ def all_suffixes(): | ||
| 'NamespaceLoader', 'OPTIMIZED_BYTECODE_SUFFIXES', 'PathFinder', | ||
| 'SOURCE_SUFFIXES', 'SourceFileLoader', 'SourcelessFileLoader', | ||
| 'WindowsRegistryFinder', 'all_suffixes'] | ||
| def __getattr__(name): | ||
| if name in ('DEBUG_BYTECODE_SUFFIXES', 'OPTIMIZED_BYTECODE_SUFFIXES', 'WindowsRegistryFinder'): | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first ifnamein ('DEBUG_BYTECODE_SUFFIXES', 'OPTIMIZED_BYTECODE_SUFFIXES'): ... elifname=='WindowsRegistryFinder': ... | ||
| if name in ('DEBUG_BYTECODE_SUFFIXES', 'OPTIMIZED_BYTECODE_SUFFIXES'): | ||
| warnings.warn(f"The '{name}' module is deprecated.", | ||
| DeprecationWarning, stacklevel=2) | ||
| return name | ||
| else: | ||
| warnings.warn(f"The '{name}' class is deprecated.", | ||
| DeprecationWarning, stacklevel=2) | ||
| return name | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| This PR adds some deprecation warnings to importlib |
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:
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
makecommand.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.abcwill produce a warning forInspectLoadereven if you're not actually using it