-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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
Changes from 1 commit
03bbac0
820ac21
d6c0645
cf8264d
cfbe079
6294458
f2458cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| """Subset of importlib.abc used to reduce importlib.util imports.""" | ||
| from . import _bootstrap | ||
| import abc | ||
| import warnings | ||
|
|
||
|
|
||
| class Loader(metaclass=abc.ABCMeta): | ||
|
|
||
| """Abstract base class for import loaders.""" | ||
| def __init__(self): | ||
| warnings.warn(f"Loader is deprecated.", | ||
| DeprecationWarning, stacklevel=2) | ||
| super().__init__() | ||
|
Comment on lines
+10
to
+13
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'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}")
Contributor
Author
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. 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
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 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, |
||
|
|
||
| def create_module(self, spec): | ||
| """Return a module to initialize and into which to load. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| """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 +27,13 @@ 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' ): | ||
|
rashansmith marked this conversation as resolved.
Outdated
|
||
| warnings.warn(f"The '{name}' module suffix is deprecated.", | ||
|
rashansmith marked this conversation as resolved.
Outdated
|
||
| DeprecationWarning, stacklevel=2) | ||
| if name == 'DEBUG_BYTECODE_SUFFIXES': | ||
| return 1 | ||
| else: | ||
| return 2 | ||
|
rashansmith marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.