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

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

Issue 21720: "TypeError: Item in ``from list'' not a string" message
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | Lib/test/test_importlib/import_/test_api.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Core implementation of import. 1 """Core implementation of 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 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 """ 996 """
997 # The hell that is fromlist ... 997 # The hell that is fromlist ...
998 # If a package was imported, try to import stuff from fromlist. 998 # If a package was imported, try to import stuff from fromlist.
999 if hasattr(module, '__path__'): 999 if hasattr(module, '__path__'):
1000 if '*' in fromlist: 1000 if '*' in fromlist:
1001 fromlist = list(fromlist) 1001 fromlist = list(fromlist)
1002 fromlist.remove('*') 1002 fromlist.remove('*')
1003 if hasattr(module, '__all__'): 1003 if hasattr(module, '__all__'):
1004 fromlist.extend(module.__all__) 1004 fromlist.extend(module.__all__)
1005 for x in fromlist: 1005 for x in fromlist:
1006 if not isinstance(x, str):
1007 raise TypeError(
1008 f"Item in 'from list' must be str, not {type(x).__name__!r}"
1009 )
1006 if not hasattr(module, x): 1010 if not hasattr(module, x):
1007 from_name = '{}.{}'.format(module.__name__, x) 1011 from_name = '{}.{}'.format(module.__name__, x)
1008 try: 1012 try:
1009 _call_with_frames_removed(import_, from_name) 1013 _call_with_frames_removed(import_, from_name)
1010 except ModuleNotFoundError as exc: 1014 except ModuleNotFoundError as exc:
1011 # Backwards-compatibility dictates we ignore failed 1015 # Backwards-compatibility dictates we ignore failed
1012 # imports triggered by fromlist for modules that don't 1016 # imports triggered by fromlist for modules that don't
1013 # exist. 1017 # exist.
1014 if exc.name == from_name: 1018 if exc.name == from_name:
1015 continue 1019 continue
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 """Install importlib as the implementation of import.""" 1141 """Install importlib as the implementation of import."""
1138 _setup(sys_module, _imp_module) 1142 _setup(sys_module, _imp_module)
1139 1143
1140 sys.meta_path.append(BuiltinImporter) 1144 sys.meta_path.append(BuiltinImporter)
1141 sys.meta_path.append(FrozenImporter) 1145 sys.meta_path.append(FrozenImporter)
1142 1146
1143 global _bootstrap_external 1147 global _bootstrap_external
1144 import _frozen_importlib_external 1148 import _frozen_importlib_external
1145 _bootstrap_external = _frozen_importlib_external 1149 _bootstrap_external = _frozen_importlib_external
1146 _frozen_importlib_external._install(sys.modules[__name__]) 1150 _frozen_importlib_external._install(sys.modules[__name__])
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_importlib/import_/test_api.py » ('j') | no next file with comments »

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