Skip to content

bpo-40050: Fix importlib._bootstrap_external #19135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -730,7 +730,7 @@ def _search_registry(cls, fullname):
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
Expand Down Expand Up @@ -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', ['\\', '/'])
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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`.
Loading