Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 558823a

Browse files
committed
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.
1 parent 4f38cb4 commit 558823a

4 files changed

Lines changed: 3 additions & 6 deletions

File tree

Lib/importlib/abc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from . import machinery
55
try:
66
import _frozen_importlib
7-
# import _frozen_importlib_external
87
except ImportError as exc:
98
if exc.name != '_frozen_importlib':
109
raise

Lib/importlib/util.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ class LazyLoader(abc.Loader):
263263
def __check_eager_loader(loader):
264264
if not hasattr(loader, 'exec_module'):
265265
raise TypeError('loader must define exec_module()')
266-
elif hasattr(loader.__class__, 'create_module'):
267-
if abc.Loader.create_module != loader.__class__.create_module:
268-
# Only care if create_module() is overridden in a subclass of
269-
# importlib.abc.Loader.
270-
raise TypeError('loader cannot define create_module()')
271266

272267
@classmethod
273268
def factory(cls, loader):

Lib/test/test_importlib/test_lazy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class LazyLoaderTests(unittest.TestCase):
5454

5555
def test_init(self):
5656
with self.assertRaises(TypeError):
57+
# Classes that dono't define exec_module() trigger TypeError.
5758
util.LazyLoader(object)
5859

5960
def new_module(self, source_code=None):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Core and Builtins
7676
Library
7777
-------
7878

79+
- Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
80+
7981
- Issue #26367: importlib.__init__() raises RuntimeError like
8082
builtins.__import__() when ``level`` is specified but without an accompanying
8183
package specified.

0 commit comments

Comments
 (0)