mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #28026: Raise ImportError when exec_module() exists but create_module() is missing.
This commit is contained in:
parent
e58571b7ea
commit
f3fd06a2e4
4 changed files with 902 additions and 910 deletions
|
@ -559,9 +559,8 @@ def module_from_spec(spec):
|
||||||
# module creation should be used.
|
# module creation should be used.
|
||||||
module = spec.loader.create_module(spec)
|
module = spec.loader.create_module(spec)
|
||||||
elif hasattr(spec.loader, 'exec_module'):
|
elif hasattr(spec.loader, 'exec_module'):
|
||||||
_warnings.warn('starting in Python 3.6, loaders defining exec_module() '
|
raise ImportError('loaders that define exec_module() '
|
||||||
'must also define create_module()',
|
'must also define create_module()')
|
||||||
DeprecationWarning, stacklevel=2)
|
|
||||||
if module is None:
|
if module is None:
|
||||||
module = _new_module(spec.name)
|
module = _new_module(spec.name)
|
||||||
_init_module_attrs(spec, module)
|
_init_module_attrs(spec, module)
|
||||||
|
|
|
@ -47,14 +47,8 @@ class ModuleFromSpecTests:
|
||||||
def exec_module(self, module):
|
def exec_module(self, module):
|
||||||
pass
|
pass
|
||||||
spec = self.machinery.ModuleSpec('test', Loader())
|
spec = self.machinery.ModuleSpec('test', Loader())
|
||||||
with warnings.catch_warnings(record=True) as w:
|
with self.assertRaises(ImportError):
|
||||||
warnings.simplefilter('always')
|
|
||||||
module = self.util.module_from_spec(spec)
|
module = self.util.module_from_spec(spec)
|
||||||
self.assertEqual(1, len(w))
|
|
||||||
self.assertTrue(issubclass(w[0].category, DeprecationWarning))
|
|
||||||
self.assertIn('create_module', str(w[0].message))
|
|
||||||
self.assertIsInstance(module, types.ModuleType)
|
|
||||||
self.assertEqual(module.__name__, spec.name)
|
|
||||||
|
|
||||||
def test_create_module_returns_None(self):
|
def test_create_module_returns_None(self):
|
||||||
class Loader(self.abc.Loader):
|
class Loader(self.abc.Loader):
|
||||||
|
|
|
@ -6968,6 +6968,9 @@ Core and Builtins
|
||||||
|
|
||||||
- Issue #19369: Optimized the usage of __length_hint__().
|
- Issue #19369: Optimized the usage of __length_hint__().
|
||||||
|
|
||||||
|
- Issue #28026: Raise ImportError when exec_module() exists but
|
||||||
|
create_module() is missing.
|
||||||
|
|
||||||
- Issue #18603: Ensure that PyOS_mystricmp and PyOS_mystrnicmp are in the
|
- Issue #18603: Ensure that PyOS_mystricmp and PyOS_mystrnicmp are in the
|
||||||
Python executable and not removed by the linker's optimizer.
|
Python executable and not removed by the linker's optimizer.
|
||||||
|
|
||||||
|
|
1796
Python/importlib.h
1796
Python/importlib.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue