Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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
bpo-40050: Fix importlib._bootstrap_external
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".
  • Loading branch information
vstinner committed Mar 24, 2020
commit 6cc525ec6d5414a979de6f0017aeff5cb29fdc4f
34 changes: 13 additions & 21 deletions 34 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:
brettcannon marked this conversation as resolved.
Show resolved Hide resolved
``_thread`` and ``_weakref``. Avoid creating a new ``winreg`` builtin module if
it's already available in :data:`sys.modules`.
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.