Commit 558823a0 authored by Brett Cannon's avatar Brett Cannon

Issue #26186: Remove an invalid type check in

importlib.util.LazyLoader.

The class was checking its argument as to whether its implementation
of create_module() came directly from importlib.abc.Loader. The
problem is that the classes coming from imoprtlib.machinery do not
directly inherit from the ABC as they come from _frozen_importlib.
Because the documentation has always said that create_module() was
ignored, the check has simply been removed.
parent 4f38cb41
...@@ -4,7 +4,6 @@ from . import _bootstrap_external ...@@ -4,7 +4,6 @@ from . import _bootstrap_external
from . import machinery from . import machinery
try: try:
import _frozen_importlib import _frozen_importlib
# import _frozen_importlib_external
except ImportError as exc: except ImportError as exc:
if exc.name != '_frozen_importlib': if exc.name != '_frozen_importlib':
raise raise
......
...@@ -263,11 +263,6 @@ class LazyLoader(abc.Loader): ...@@ -263,11 +263,6 @@ class LazyLoader(abc.Loader):
def __check_eager_loader(loader): def __check_eager_loader(loader):
if not hasattr(loader, 'exec_module'): if not hasattr(loader, 'exec_module'):
raise TypeError('loader must define exec_module()') raise TypeError('loader must define exec_module()')
elif hasattr(loader.__class__, 'create_module'):
if abc.Loader.create_module != loader.__class__.create_module:
# Only care if create_module() is overridden in a subclass of
# importlib.abc.Loader.
raise TypeError('loader cannot define create_module()')
@classmethod @classmethod
def factory(cls, loader): def factory(cls, loader):
......
...@@ -54,6 +54,7 @@ class LazyLoaderTests(unittest.TestCase): ...@@ -54,6 +54,7 @@ class LazyLoaderTests(unittest.TestCase):
def test_init(self): def test_init(self):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
# Classes that dono't define exec_module() trigger TypeError.
util.LazyLoader(object) util.LazyLoader(object)
def new_module(self, source_code=None): def new_module(self, source_code=None):
......
...@@ -76,6 +76,8 @@ Core and Builtins ...@@ -76,6 +76,8 @@ Core and Builtins
Library Library
------- -------
- Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
- Issue #26367: importlib.__init__() raises RuntimeError like - Issue #26367: importlib.__init__() raises RuntimeError like
builtins.__import__() when ``level`` is specified but without an accompanying builtins.__import__() when ``level`` is specified but without an accompanying
package specified. package specified.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment