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

Delta Between Two Patch Sets: Lib/importlib/_bootstrap_external.py

Issue 27095: Simplify MAKE_FUNCTION
Left Patch Set: Created 3 years, 3 months ago
Right Patch Set: Created 3 years, 3 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 """Core implementation of path-based import. 1 """Core implementation of path-based import.
2 2
3 This module is NOT meant to be directly imported! It has been designed such 3 This module is NOT meant to be directly imported! It has been designed such
4 that it can be bootstrapped into Python as the implementation of import. As 4 that it can be bootstrapped into Python as the implementation of import. As
5 such it requires the injection of specific modules and attributes in order to 5 such it requires the injection of specific modules and attributes in order to
6 work. One should use importlib as the public-facing version of this module. 6 work. One should use importlib as the public-facing version of this module.
7 7
8 """ 8 """
9 # 9 #
10 # IMPORTANT: Whenever making changes to this module, be sure to run 10 # IMPORTANT: Whenever making changes to this module, be sure to run
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 123
124 # Finder/loader utility code ############################################### 124 # Finder/loader utility code ###############################################
125 125
126 # Magic word to reject .pyc files generated by other Python versions. 126 # Magic word to reject .pyc files generated by other Python versions.
127 # It should change for each incompatible change to the bytecode. 127 # It should change for each incompatible change to the bytecode.
128 # 128 #
129 # The value of CR and LF is incorporated so if you ever read or write 129 # The value of CR and LF is incorporated so if you ever read or write
130 # a .pyc file in text mode the magic number will be wrong; also, the 130 # a .pyc file in text mode the magic number will be wrong; also, the
131 # Apple MPW compiler swaps their values, botching string constants. 131 # Apple MPW compiler swaps their values, botching string constants.
132 #
133 # The magic numbers must be spaced apart at least 2 values, as the
134 # -U interpeter flag will cause MAGIC+1 being used. They have been
135 # odd numbers for some time now.
136 # 132 #
137 # There were a variety of old schemes for setting the magic number. 133 # There were a variety of old schemes for setting the magic number.
138 # The current working scheme is to increment the previous value by 134 # The current working scheme is to increment the previous value by
139 # 10. 135 # 10.
140 # 136 #
141 # Starting with the adoption of PEP 3147 in Python 3.2, every bump in magic 137 # Starting with the adoption of PEP 3147 in Python 3.2, every bump in magic
142 # number also includes a new "magic tag", i.e. a human readable string used 138 # number also includes a new "magic tag", i.e. a human readable string used
143 # to represent the magic number in __pycache__ directories. When you change 139 # to represent the magic number in __pycache__ directories. When you change
144 # the magic number, you must also set a new unique magic tag. Generally this 140 # the magic number, you must also set a new unique magic tag. Generally this
145 # can be named after the Python major version of the magic number bump, but 141 # can be named after the Python major version of the magic number bump, but
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 # free vars) 212 # free vars)
217 # Python 3.4a1 3270 (various tweaks to the __class__ closure) 213 # Python 3.4a1 3270 (various tweaks to the __class__ closure)
218 # Python 3.4a1 3280 (remove implicit class argument) 214 # Python 3.4a1 3280 (remove implicit class argument)
219 # Python 3.4a4 3290 (changes to __qualname__ computation) 215 # Python 3.4a4 3290 (changes to __qualname__ computation)
220 # Python 3.4a4 3300 (more changes to __qualname__ computation) 216 # Python 3.4a4 3300 (more changes to __qualname__ computation)
221 # Python 3.4rc2 3310 (alter __qualname__ computation) 217 # Python 3.4rc2 3310 (alter __qualname__ computation)
222 # Python 3.5a0 3320 (matrix multiplication operator) 218 # Python 3.5a0 3320 (matrix multiplication operator)
223 # Python 3.5b1 3330 (PEP 448: Additional Unpacking Generalizations) 219 # Python 3.5b1 3330 (PEP 448: Additional Unpacking Generalizations)
224 # Python 3.5b2 3340 (fix dictionary display evaluation order #11205) 220 # Python 3.5b2 3340 (fix dictionary display evaluation order #11205)
225 # Python 3.5b2 3350 (add GET_YIELD_FROM_ITER opcode #24400) 221 # Python 3.5b2 3350 (add GET_YIELD_FROM_ITER opcode #24400)
222 # Python 3.5.2 3351 (fix BUILD_MAP_UNPACK_WITH_CALL opcode #27286)
226 # Python 3.6a0 3360 (add FORMAT_VALUE opcode #25483 223 # Python 3.6a0 3360 (add FORMAT_VALUE opcode #25483
227 # Python 3.6a0 3361 (lineno delta of code.co_lnotab becomes signed) 224 # Python 3.6a0 3361 (lineno delta of code.co_lnotab becomes signed)
228 # Python 3.6a2 3371 (MAKE_FUNCTION simplification) 225 # Python 3.6a1 3370 (16 bit wordcode)
226 # Python 3.6a1 3371 (add BUILD_CONST_KEY_MAP opocode #27140)
227 # Python 3.6a1 3372 (MAKE_FUNCTION simplification)
229 # 228 #
230 # MAGIC must change whenever the bytecode emitted by the compiler may no 229 # MAGIC must change whenever the bytecode emitted by the compiler may no
231 # longer be understood by older implementations of the eval loop (usually 230 # longer be understood by older implementations of the eval loop (usually
232 # due to the addition of new opcodes). 231 # due to the addition of new opcodes).
233 # 232 #
234 # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array 233 # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
235 # in PC/launcher.c must also be updated. 234 # in PC/launcher.c must also be updated.
236 235
237 MAGIC_NUMBER = (3361).to_bytes(2, 'little') + b'\r\n' 236 MAGIC_NUMBER = (3372).to_bytes(2, 'little') + b'\r\n'
238 _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c 237 _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
239 238
240 _PYCACHE = '__pycache__' 239 _PYCACHE = '__pycache__'
241 _OPT = 'opt-' 240 _OPT = 'opt-'
242 241
243 SOURCE_SUFFIXES = ['.py'] # _setup() adds .pyw as needed. 242 SOURCE_SUFFIXES = ['.py'] # _setup() adds .pyw as needed.
244 243
245 BYTECODE_SUFFIXES = ['.pyc'] 244 BYTECODE_SUFFIXES = ['.pyc']
246 # Deprecated. 245 # Deprecated.
247 DEBUG_BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES = BYTECODE_SUFFIXES 246 DEBUG_BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES = BYTECODE_SUFFIXES
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 if spec is None: 1207 if spec is None:
1209 return None, [] 1208 return None, []
1210 return spec.loader, spec.submodule_search_locations or [] 1209 return spec.loader, spec.submodule_search_locations or []
1211 1210
1212 def _get_spec(self, loader_class, fullname, path, smsl, target): 1211 def _get_spec(self, loader_class, fullname, path, smsl, target):
1213 loader = loader_class(fullname, path) 1212 loader = loader_class(fullname, path)
1214 return spec_from_file_location(fullname, path, loader=loader, 1213 return spec_from_file_location(fullname, path, loader=loader,
1215 submodule_search_locations=smsl) 1214 submodule_search_locations=smsl)
1216 1215
1217 def find_spec(self, fullname, target=None): 1216 def find_spec(self, fullname, target=None):
1218 """Try to find a loader for the specified module, or the namespace 1217 """Try to find a spec for the specified module. Returns the
1219 package portions. Returns (loader, list-of-portions).""" 1218 matching spec, or None if not found."""
1220 is_namespace = False 1219 is_namespace = False
1221 tail_module = fullname.rpartition('.')[2] 1220 tail_module = fullname.rpartition('.')[2]
1222 try: 1221 try:
1223 mtime = _path_stat(self.path or _os.getcwd()).st_mtime 1222 mtime = _path_stat(self.path or _os.getcwd()).st_mtime
1224 except OSError: 1223 except OSError:
1225 mtime = -1 1224 mtime = -1
1226 if mtime != self._path_mtime: 1225 if mtime != self._path_mtime:
1227 self._fill_cache() 1226 self._fill_cache()
1228 self._path_mtime = mtime 1227 self._path_mtime = mtime
1229 # tail_module keeps the original casing, for __file__ and friends 1228 # tail_module keeps the original casing, for __file__ and friends
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 supported_loaders = _get_supported_file_loaders() 1422 supported_loaders = _get_supported_file_loaders()
1424 sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)]) 1423 sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)])
1425 if _os.__name__ == 'nt': 1424 if _os.__name__ == 'nt':
1426 sys.meta_path.append(WindowsRegistryFinder) 1425 sys.meta_path.append(WindowsRegistryFinder)
1427 sys.meta_path.append(PathFinder) 1426 sys.meta_path.append(PathFinder)
1428 1427
1429 # XXX We expose a couple of classes in _bootstrap for the sake of 1428 # XXX We expose a couple of classes in _bootstrap for the sake of
1430 # a setuptools bug (https://bitbucket.org/pypa/setuptools/issue/378). 1429 # a setuptools bug (https://bitbucket.org/pypa/setuptools/issue/378).
1431 _bootstrap_module.FileFinder = FileFinder 1430 _bootstrap_module.FileFinder = FileFinder
1432 _bootstrap_module.SourceFileLoader = SourceFileLoader 1431 _bootstrap_module.SourceFileLoader = SourceFileLoader
LEFTRIGHT

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