Skip to content

bpo-42403: Use @staticmethod in importlib #23395

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

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Lib/importlib/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,16 +761,16 @@ def find_module(cls, fullname, path=None):
spec = cls.find_spec(fullname, path)
return spec.loader if spec is not None else None

@classmethod
def create_module(self, spec):
@staticmethod
def create_module(spec):
"""Create a built-in module"""
if spec.name not in sys.builtin_module_names:
raise ImportError('{!r} is not a built-in module'.format(spec.name),
name=spec.name)
return _call_with_frames_removed(_imp.create_builtin, spec)

@classmethod
def exec_module(self, module):
@staticmethod
def exec_module(module):
"""Exec a built-in module"""
_call_with_frames_removed(_imp.exec_builtin, module)

Expand Down Expand Up @@ -831,8 +831,8 @@ def find_module(cls, fullname, path=None):
"""
return cls if _imp.is_frozen(fullname) else None

@classmethod
def create_module(cls, spec):
@staticmethod
def create_module(spec):
"""Use default semantics for module creation."""

@staticmethod
Expand Down
20 changes: 10 additions & 10 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ class WindowsRegistryFinder:
'\\Modules\\{fullname}\\Debug')
DEBUG_BUILD = (_MS_WINDOWS and '_d.pyd' in EXTENSION_SUFFIXES)

@classmethod
def _open_registry(cls, key):
@staticmethod
def _open_registry(key):
try:
return winreg.OpenKey(winreg.HKEY_CURRENT_USER, key)
except OSError:
Expand Down Expand Up @@ -1219,8 +1219,8 @@ class _NamespaceLoader:
def __init__(self, name, path, path_finder):
self._path = _NamespacePath(name, path, path_finder)

@classmethod
def module_repr(cls, module):
@staticmethod
def module_repr(module):
"""Return repr for the module.

The method is deprecated. The import machinery does the job itself.
Expand Down Expand Up @@ -1261,8 +1261,8 @@ class PathFinder:

"""Meta path finder for sys.path and package __path__ attributes."""

@classmethod
def invalidate_caches(cls):
@staticmethod
def invalidate_caches():
"""Call the invalidate_caches() method on all path entry finders
stored in sys.path_importer_caches (where implemented)."""
for name, finder in list(sys.path_importer_cache.items()):
Expand All @@ -1271,8 +1271,8 @@ def invalidate_caches(cls):
elif hasattr(finder, 'invalidate_caches'):
finder.invalidate_caches()

@classmethod
def _path_hooks(cls, path):
@staticmethod
def _path_hooks(path):
"""Search sys.path_hooks for a finder for 'path'."""
if sys.path_hooks is not None and not sys.path_hooks:
_warnings.warn('sys.path_hooks is empty', ImportWarning)
Expand Down Expand Up @@ -1390,8 +1390,8 @@ def find_module(cls, fullname, path=None):
return None
return spec.loader

@classmethod
def find_distributions(cls, *args, **kwargs):
@staticmethod
def find_distributions(*args, **kwargs):
"""
Find distributions.

Expand Down
Loading