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

Side by Side Diff: Lib/importlib/abc.py

Issue 23014: Don't have importlib.abc.Loader.create_module() be optional
Patch Set: Created 4 years, 9 months ago
Left:
Right:
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 unified diff | Download patch
OLDNEW
1 """Abstract base classes related to import.""" 1 """Abstract base classes related to import."""
2 from . import _bootstrap 2 from . import _bootstrap
3 from . import machinery 3 from . import machinery
4 try: 4 try:
5 import _frozen_importlib 5 import _frozen_importlib
6 except ImportError as exc: 6 except ImportError as exc:
7 if exc.name != '_frozen_importlib': 7 if exc.name != '_frozen_importlib':
8 raise 8 raise
9 _frozen_importlib = None 9 _frozen_importlib = None
10 import abc 10 import abc
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 class Loader(metaclass=abc.ABCMeta): 115 class Loader(metaclass=abc.ABCMeta):
116 116
117 """Abstract base class for import loaders.""" 117 """Abstract base class for import loaders."""
118 118
119 def create_module(self, spec): 119 def create_module(self, spec):
120 """Return a module to initialize and into which to load. 120 """Return a module to initialize and into which to load.
121 121
122 This method should raise ImportError if anything prevents it 122 This method should raise ImportError if anything prevents it
123 from creating a new module. It may return None to indicate 123 from creating a new module. It may return None to indicate
124 that the spec should create the new module. 124 that the spec should create the new module.
125
126 create_module() is optional.
127
128 """ 125 """
129 # By default, defer to default semantics for the new module. 126 # By default, defer to default semantics for the new module.
130 return None 127 return None
131 128
132 # We don't define exec_module() here since that would break 129 # We don't define exec_module() here since that would break
133 # hasattr checks we do to support backward compatibility. 130 # hasattr checks we do to support backward compatibility.
134 131
135 def load_module(self, fullname): 132 def load_module(self, fullname):
136 """Return the loaded module. 133 """Return the loaded module.
137 134
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 """Write the bytes to the path (if possible). 312 """Write the bytes to the path (if possible).
316 313
317 Accepts a str path and data as bytes. 314 Accepts a str path and data as bytes.
318 315
319 Any needed intermediary directories are to be created. If for some 316 Any needed intermediary directories are to be created. If for some
320 reason the file cannot be written because of permissions, fail 317 reason the file cannot be written because of permissions, fail
321 silently. 318 silently.
322 """ 319 """
323 320
324 _register(SourceLoader, machinery.SourceFileLoader) 321 _register(SourceLoader, machinery.SourceFileLoader)
OLDNEW

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