summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-05-11 18:48:41 (GMT)
committerBrett Cannon <brett@python.org>2012-05-11 18:48:41 (GMT)
commitc049952de76cbcd00e490e48445ed7a50d3dc83a (patch)
tree91d1ff6bffbb8d6c5b04a8bae6b53944eb078335 /Lib/importlib/_bootstrap.py
parent0c59b039b86afa9f51c30f7d9f340d9c75984488 (diff)
downloadcpython-c049952de76cbcd00e490e48445ed7a50d3dc83a.zip
cpython-c049952de76cbcd00e490e48445ed7a50d3dc83a.tar.gz
cpython-c049952de76cbcd00e490e48445ed7a50d3dc83a.tar.bz2
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().
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index ce23043..41b96a9 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -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)
@@ -614,6 +616,11 @@ class FileLoader:
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."""
return self.path
@@ -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