fix pip module resolution (#78000)

* `importlib.util` appears to be lazily imported and is sometimes unavailable as an attribute of `importlib` without an explicit import
This commit is contained in:
Matt Davis
2022-06-08 09:56:17 -07:00
committed by GitHub
parent db335498d0
commit 6e78425f8d
2 changed files with 6 additions and 4 deletions
+2
View File
@@ -0,0 +1,2 @@
bugfixes:
- pip - fix cases where resolution of pip Python module fails when importlib.util has not already been imported
+4 -4
View File
@@ -455,15 +455,15 @@ def _get_pip(module, env=None, executable=None):
def _have_pip_module(): # type: () -> bool
"""Return True if the `pip` module can be found using the current Python interpreter, otherwise return False."""
try:
import importlib
from importlib.util import find_spec
except ImportError:
importlib = None # type: types.ModuleType | None # type: ignore[no-redef]
find_spec = None # type: ignore[assignment] # type: ignore[no-redef]
if importlib:
if find_spec:
# noinspection PyBroadException
try:
# noinspection PyUnresolvedReferences
found = bool(importlib.util.find_spec('pip'))
found = bool(find_spec('pip'))
except Exception:
found = False
else: