Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(179096)

Unified Diff: Lib/importlib/_bootstrap.py

Issue 23014: Don't have importlib.abc.Loader.create_module() be optional
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
--- a/Lib/importlib/_bootstrap.py Fri Dec 12 12:00:02 2014 -0500
+++ b/Lib/importlib/_bootstrap.py Fri Dec 12 12:23:43 2014 -0500
@@ -1055,6 +1055,10 @@
# If create_module() returns `None` then it means default
# module creation should be used.
module = spec.loader.create_module(spec)
+ elif hasattr(spec.loader, 'exec_module'):
+ _warnings.warn('starting in Python 3.6, loaders defining exec_module() '
+ 'must also define create_module()',
+ DeprecationWarning)
berkerpeksag 2014/12/12 20:07:45 Shouldn't the stacklevel parameter be 2 here?
brett.cannon 2014/12/15 15:54:58 It's a bit tricky to get right. Yes, it should at
brett.cannon 2015/01/09 17:28:56 Done.
if module is None:
module = _new_module(spec.name)
_init_module_attrs(spec, module)
@@ -1299,6 +1303,10 @@
return cls if _imp.is_frozen(fullname) else None
@staticmethod
eric.snow 2014/12/16 03:42:16 Out of curiousity, what is the advantage of static
brett.cannon 2014/12/16 16:04:13 I don't explicitly remember him saying that, but f
brett.cannon 2015/01/09 17:28:56 Went ahead and made it a classmethod.
+ def create_module(spec):
+ """Use default semantics for module creation."""
+
+ @staticmethod
def exec_module(module):
name = module.__spec__.name
if not _imp.is_frozen(name):
@@ -1411,6 +1419,9 @@
tail_name = fullname.rpartition('.')[2]
return filename_base == '__init__' and tail_name != '__init__'
+ def create_module(self, spec):
+ """Use default semantics for module creation."""
+
def exec_module(self, module):
"""Execute the module."""
code = self.get_code(module.__name__)
@@ -1771,6 +1782,9 @@
def get_code(self, fullname):
return compile('', '<string>', 'exec', dont_inherit=True)
+ def create_module(self, spec):
+ """Use default semantics for module creation."""
+
def exec_module(self, module):
pass

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+