summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-03-24 17:03:34 (GMT)
committerGitHub <noreply@github.com>2020-03-24 17:03:34 (GMT)
commit83d46e0622d2efdf5f3bf8bf8904d0dcb55fc322 (patch)
tree902e9867f805e6a67ad3a66cf928c7023afeec23 /Lib/importlib
parent9b8e74ca77da7167033917d155e5f55c67b92f14 (diff)
downloadcpython-83d46e0622d2efdf5f3bf8bf8904d0dcb55fc322.zip
cpython-83d46e0622d2efdf5f3bf8bf8904d0dcb55fc322.tar.gz
cpython-83d46e0622d2efdf5f3bf8bf8904d0dcb55fc322.tar.bz2
bpo-40050: Fix importlib._bootstrap_external (GH-19135)
Remove two unused imports: _thread and _weakref. Avoid creating a new winreg builtin module if it's already available in sys.modules. The winreg module is now stored as "winreg" rather than "_winreg".
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap_external.py34
1 files changed, 13 insertions, 21 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 7353bf9..25a3f8c 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -716,9 +716,9 @@ class WindowsRegistryFinder:
@classmethod
def _open_registry(cls, key):
try:
- return _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key)
+ return winreg.OpenKey(winreg.HKEY_CURRENT_USER, key)
except OSError:
- return _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key)
+ return winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key)
@classmethod
def _search_registry(cls, fullname):
@@ -730,7 +730,7 @@ class WindowsRegistryFinder:
sys_version='%d.%d' % sys.version_info[:2])
try:
with cls._open_registry(key) as hkey:
- filepath = _winreg.QueryValue(hkey, '')
+ filepath = winreg.QueryValue(hkey, '')
except OSError:
return None
return filepath
@@ -1584,14 +1584,7 @@ def _setup(_bootstrap_module):
sys = _bootstrap.sys
_imp = _bootstrap._imp
- # Directly load built-in modules needed during bootstrap.
self_module = sys.modules[__name__]
- for builtin_name in ('_io', '_warnings', 'builtins', 'marshal'):
- if builtin_name not in sys.modules:
- builtin_module = _bootstrap._builtin_from_name(builtin_name)
- else:
- builtin_module = sys.modules[builtin_name]
- setattr(self_module, builtin_name, builtin_module)
# Directly load the os module (needed during bootstrap).
os_details = ('posix', ['/']), ('nt', ['\\', '/'])
@@ -1610,23 +1603,22 @@ def _setup(_bootstrap_module):
continue
else:
raise ImportError('importlib requires posix or nt')
+
setattr(self_module, '_os', os_module)
setattr(self_module, 'path_sep', path_sep)
setattr(self_module, 'path_separators', ''.join(path_separators))
setattr(self_module, '_pathseps_with_colon', {f':{s}' for s in path_separators})
- # Directly load the _thread module (needed during bootstrap).
- thread_module = _bootstrap._builtin_from_name('_thread')
- setattr(self_module, '_thread', thread_module)
-
- # Directly load the _weakref module (needed during bootstrap).
- weakref_module = _bootstrap._builtin_from_name('_weakref')
- setattr(self_module, '_weakref', weakref_module)
-
- # Directly load the winreg module (needed during bootstrap).
+ # Directly load built-in modules needed during bootstrap.
+ builtin_names = ['_io', '_warnings', 'marshal']
if builtin_os == 'nt':
- winreg_module = _bootstrap._builtin_from_name('winreg')
- setattr(self_module, '_winreg', winreg_module)
+ builtin_names.append('winreg')
+ for builtin_name in builtin_names:
+ if builtin_name not in sys.modules:
+ builtin_module = _bootstrap._builtin_from_name(builtin_name)
+ else:
+ builtin_module = sys.modules[builtin_name]
+ setattr(self_module, builtin_name, builtin_module)
# Constants
setattr(self_module, '_relax_case', _make_relax_case())