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

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

Issue 15502: Meta path finders and path entry finders are different, but share an ABC
Left Patch Set: Created 9 months, 3 weeks ago
Right Patch Set: Created 9 months, 3 weeks 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:
Right: Side by side diff | Download
LEFTRIGHT
(no file at all)
1 """A pure Python implementation of import.""" 1 """A pure Python implementation of import."""
2 __all__ = ['__import__', 'import_module', 'invalidate_caches'] 2 __all__ = ['__import__', 'import_module', 'invalidate_caches']
3 3
4 # Bootstrap help ##################################################### 4 # Bootstrap help #####################################################
5 5
6 # Until bootstrapping is complete, DO NOT import any modules that attempt 6 # Until bootstrapping is complete, DO NOT import any modules that attempt
7 # to import importlib._bootstrap (directly or indirectly). Since this 7 # to import importlib._bootstrap (directly or indirectly). Since this
8 # partially initialised package would be present in sys.modules, those 8 # partially initialised package would be present in sys.modules, those
9 # modules would get an uninitialised copy of the source version, instead 9 # modules would get an uninitialised copy of the source version, instead
10 # of a fully initialised version (either the frozen one or the one 10 # of a fully initialised version (either the frozen one or the one
(...skipping 20 matching lines...) Expand all
31 31
32 # Fully bootstrapped at this point, import whatever you like, circular 32 # Fully bootstrapped at this point, import whatever you like, circular
33 # dependencies and startup overhead minimisation permitting :) 33 # dependencies and startup overhead minimisation permitting :)
34 34
35 # Public API ######################################################### 35 # Public API #########################################################
36 36
37 from ._bootstrap import __import__ 37 from ._bootstrap import __import__
38 38
39 39
40 def invalidate_caches(): 40 def invalidate_caches():
41 """Call the invalidate_caches() method on all finders stored in 41 """Call the invalidate_caches() method on all meta path finders stored in
42 sys.path_importer_caches (where implemented).""" 42 sys.meta_path (where implemented)."""
43 for finder in sys.path_importer_cache.values(): 43 for finder in sys.meta_path:
44 if hasattr(finder, 'invalidate_caches'): 44 if hasattr(finder, 'invalidate_caches'):
45 finder.invalidate_caches() 45 finder.invalidate_caches()
46 46
47 47
48 def find_loader(name, path=None): 48 def find_loader(name, path=None):
49 """Find the loader for the specified module. 49 """Find the loader for the specified module.
50 50
51 First, sys.modules is checked to see if the module was already imported. If 51 First, sys.modules is checked to see if the module was already imported. If
52 so, then sys.modules[name].__loader__ is returned. If that happens to be 52 so, then sys.modules[name].__loader__ is returned. If that happens to be
53 set to None, then ValueError is raised. If the module is not in 53 set to None, then ValueError is raised. If the module is not in
(...skipping 25 matching lines...) Expand all
79 """ 79 """
80 level = 0 80 level = 0
81 if name.startswith('.'): 81 if name.startswith('.'):
82 if not package: 82 if not package:
83 raise TypeError("relative imports require the 'package' argument") 83 raise TypeError("relative imports require the 'package' argument")
84 for character in name: 84 for character in name:
85 if character != '.': 85 if character != '.':
86 break 86 break
87 level += 1 87 level += 1
88 return _bootstrap._gcd_import(name[level:], package, level) 88 return _bootstrap._gcd_import(name[level:], package, level)
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7