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:
Brett Cannon 2012-05-11 14:48:41 -04:00
parent 0c59b039b8
commit c049952de7
9 changed files with 2485 additions and 2392 deletions

View file

@ -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