mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Issue #23014: Make importlib.abc.Loader.create_module() required when
importlib.abc.Loader.exec_module() is also defined. Before this change, create_module() was optional **and** could return None to trigger default semantics. This change now reduces the options for choosing default semantics to one and in the most backporting-friendly way (define create_module() to return None).
This commit is contained in:
parent
863c69cfeb
commit
02d8454002
11 changed files with 2440 additions and 2347 deletions
|
@ -41,10 +41,16 @@ class DecodeSourceBytesTests:
|
|||
class ModuleFromSpecTests:
|
||||
|
||||
def test_no_create_module(self):
|
||||
class Loader(self.abc.Loader):
|
||||
pass
|
||||
class Loader:
|
||||
def exec_module(self, module):
|
||||
pass
|
||||
spec = self.machinery.ModuleSpec('test', Loader())
|
||||
module = self.util.module_from_spec(spec)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue