mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
Issue #13959: Have
importlib.abc.FileLoader.load_module()/get_filename() and importlib.machinery.ExtensionFileLoader.load_module() have their single argument be optional as the loader's constructor has all the ncessary information. This allows for the deprecation of imp.load_source()/load_compile()/load_package().
This commit is contained in:
parent
0c59b039b8
commit
c049952de7
9 changed files with 2485 additions and 2392 deletions
|
@ -282,8 +282,10 @@ def _check_name(method):
|
|||
compared against. If the comparison fails then ImportError is raised.
|
||||
|
||||
"""
|
||||
def _check_name_wrapper(self, name, *args, **kwargs):
|
||||
if self.name != name:
|
||||
def _check_name_wrapper(self, name=None, *args, **kwargs):
|
||||
if name is None:
|
||||
name = self.name
|
||||
elif self.name != name:
|
||||
raise ImportError("loader cannot handle %s" % name, name=name)
|
||||
return method(self, name, *args, **kwargs)
|
||||
_wrap(_check_name_wrapper, method)
|
||||
|
@ -613,6 +615,11 @@ class FileLoader:
|
|||
self.name = fullname
|
||||
self.path = path
|
||||
|
||||
@_check_name
|
||||
def load_module(self, fullname):
|
||||
"""Load a module from a file."""
|
||||
return super().load_module(fullname)
|
||||
|
||||
@_check_name
|
||||
def get_filename(self, fullname):
|
||||
"""Return the path to the source file as found by the finder."""
|
||||
|
@ -713,17 +720,14 @@ class ExtensionFileLoader:
|
|||
del sys.modules[fullname]
|
||||
raise
|
||||
|
||||
@_check_name
|
||||
def is_package(self, fullname):
|
||||
"""Return False as an extension module can never be a package."""
|
||||
return False
|
||||
|
||||
@_check_name
|
||||
def get_code(self, fullname):
|
||||
"""Return None as an extension module cannot create a code object."""
|
||||
return None
|
||||
|
||||
@_check_name
|
||||
def get_source(self, fullname):
|
||||
"""Return None as extension modules have no source code."""
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue