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

Skip to content

Commit f3fd06a

Browse files
Issue #28026: Raise ImportError when exec_module() exists but create_module() is missing.
1 parent e58571b commit f3fd06a

4 files changed

Lines changed: 901 additions & 909 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,8 @@ def module_from_spec(spec):
559559
# module creation should be used.
560560
module = spec.loader.create_module(spec)
561561
elif hasattr(spec.loader, 'exec_module'):
562-
_warnings.warn('starting in Python 3.6, loaders defining exec_module() '
563-
'must also define create_module()',
564-
DeprecationWarning, stacklevel=2)
562+
raise ImportError('loaders that define exec_module() '
563+
'must also define create_module()')
565564
if module is None:
566565
module = _new_module(spec.name)
567566
_init_module_attrs(spec, module)

Lib/test/test_importlib/test_util.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ class Loader:
4747
def exec_module(self, module):
4848
pass
4949
spec = self.machinery.ModuleSpec('test', Loader())
50-
with warnings.catch_warnings(record=True) as w:
51-
warnings.simplefilter('always')
50+
with self.assertRaises(ImportError):
5251
module = self.util.module_from_spec(spec)
53-
self.assertEqual(1, len(w))
54-
self.assertTrue(issubclass(w[0].category, DeprecationWarning))
55-
self.assertIn('create_module', str(w[0].message))
56-
self.assertIsInstance(module, types.ModuleType)
57-
self.assertEqual(module.__name__, spec.name)
5852

5953
def test_create_module_returns_None(self):
6054
class Loader(self.abc.Loader):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6968,6 +6968,9 @@ Core and Builtins
69686968

69696969
- Issue #19369: Optimized the usage of __length_hint__().
69706970

6971+
- Issue #28026: Raise ImportError when exec_module() exists but
6972+
create_module() is missing.
6973+
69716974
- Issue #18603: Ensure that PyOS_mystricmp and PyOS_mystrnicmp are in the
69726975
Python executable and not removed by the linker's optimizer.
69736976

0 commit comments

Comments
 (0)