mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
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".
This commit is contained in:
parent
9b8e74ca77
commit
83d46e0622
3 changed files with 1756 additions and 1768 deletions
|
@ -716,9 +716,9 @@ class WindowsRegistryFinder:
|
||||||
@classmethod
|
@classmethod
|
||||||
def _open_registry(cls, key):
|
def _open_registry(cls, key):
|
||||||
try:
|
try:
|
||||||
return _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key)
|
return winreg.OpenKey(winreg.HKEY_CURRENT_USER, key)
|
||||||
except OSError:
|
except OSError:
|
||||||
return _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key)
|
return winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _search_registry(cls, fullname):
|
def _search_registry(cls, fullname):
|
||||||
|
@ -730,7 +730,7 @@ class WindowsRegistryFinder:
|
||||||
sys_version='%d.%d' % sys.version_info[:2])
|
sys_version='%d.%d' % sys.version_info[:2])
|
||||||
try:
|
try:
|
||||||
with cls._open_registry(key) as hkey:
|
with cls._open_registry(key) as hkey:
|
||||||
filepath = _winreg.QueryValue(hkey, '')
|
filepath = winreg.QueryValue(hkey, '')
|
||||||
except OSError:
|
except OSError:
|
||||||
return None
|
return None
|
||||||
return filepath
|
return filepath
|
||||||
|
@ -1584,14 +1584,7 @@ def _setup(_bootstrap_module):
|
||||||
sys = _bootstrap.sys
|
sys = _bootstrap.sys
|
||||||
_imp = _bootstrap._imp
|
_imp = _bootstrap._imp
|
||||||
|
|
||||||
# Directly load built-in modules needed during bootstrap.
|
|
||||||
self_module = sys.modules[__name__]
|
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).
|
# Directly load the os module (needed during bootstrap).
|
||||||
os_details = ('posix', ['/']), ('nt', ['\\', '/'])
|
os_details = ('posix', ['/']), ('nt', ['\\', '/'])
|
||||||
|
@ -1610,23 +1603,22 @@ def _setup(_bootstrap_module):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
raise ImportError('importlib requires posix or nt')
|
raise ImportError('importlib requires posix or nt')
|
||||||
|
|
||||||
setattr(self_module, '_os', os_module)
|
setattr(self_module, '_os', os_module)
|
||||||
setattr(self_module, 'path_sep', path_sep)
|
setattr(self_module, 'path_sep', path_sep)
|
||||||
setattr(self_module, 'path_separators', ''.join(path_separators))
|
setattr(self_module, 'path_separators', ''.join(path_separators))
|
||||||
setattr(self_module, '_pathseps_with_colon', {f':{s}' for s in path_separators})
|
setattr(self_module, '_pathseps_with_colon', {f':{s}' for s in path_separators})
|
||||||
|
|
||||||
# Directly load the _thread module (needed during bootstrap).
|
# Directly load built-in modules needed during bootstrap.
|
||||||
thread_module = _bootstrap._builtin_from_name('_thread')
|
builtin_names = ['_io', '_warnings', 'marshal']
|
||||||
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).
|
|
||||||
if builtin_os == 'nt':
|
if builtin_os == 'nt':
|
||||||
winreg_module = _bootstrap._builtin_from_name('winreg')
|
builtin_names.append('winreg')
|
||||||
setattr(self_module, '_winreg', winreg_module)
|
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
|
# Constants
|
||||||
setattr(self_module, '_relax_case', _make_relax_case())
|
setattr(self_module, '_relax_case', _make_relax_case())
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fix ``importlib._bootstrap_external``. Remove two unused imports importlib:
|
||||||
|
``_thread`` and ``_weakref``. Avoid creating a new ``winreg`` builtin module if
|
||||||
|
it's already available in :data:`sys.modules`.
|
3487
Python/importlib_external.h
generated
3487
Python/importlib_external.h
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue