]> granicus.if.org Git - python/commitdiff
Issue #26186: Remove an invalid type check in
authorBrett Cannon <brett@python.org>
Sun, 21 Feb 2016 02:35:41 +0000 (18:35 -0800)
committerBrett Cannon <brett@python.org>
Sun, 21 Feb 2016 02:35:41 +0000 (18:35 -0800)
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.

Lib/importlib/abc.py
Lib/importlib/util.py
Lib/test/test_importlib/test_lazy.py
Misc/NEWS

index 11af22dab9ba7ee3955535e6a787dc12445bafb8..daff681e69689f4884bb2f9d95a94777d80d309e 100644 (file)
@@ -4,7 +4,6 @@ from . import _bootstrap_external
 from . import machinery
 try:
     import _frozen_importlib
-#    import _frozen_importlib_external
 except ImportError as exc:
     if exc.name != '_frozen_importlib':
         raise
index 1dbff2605eaed031fc5cbb149d37bc8ec84f7fbd..4525b3f78e46a17e5ea60a9f46e626a8431afeff 100644 (file)
@@ -263,11 +263,6 @@ class LazyLoader(abc.Loader):
     def __check_eager_loader(loader):
         if not hasattr(loader, '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
     def factory(cls, loader):
index 2e191bbf5cab952fc4281a90d0eaafdc7c56cbbf..774b7a4564119ad48db9ab468d47c6f0ebb17e56 100644 (file)
@@ -54,6 +54,7 @@ class LazyLoaderTests(unittest.TestCase):
 
     def test_init(self):
         with self.assertRaises(TypeError):
+            # Classes that dono't define exec_module() trigger TypeError.
             util.LazyLoader(object)
 
     def new_module(self, source_code=None):
index cb42e27eb301702aa3b1cd7e72ddf4e515e85584..66d96132f3b06d22f4164795fc9449fe6c51f837 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -76,6 +76,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
+
 - Issue #26367: importlib.__init__() raises RuntimeError like
   builtins.__import__() when ``level`` is specified but without an accompanying
   package specified.