summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-01-05 23:21:43 -0500
committerJason R. Coombs <jaraco@jaraco.com>2022-01-05 23:22:26 -0500
commit2504699e5f9acfdd1438512173f90b3f61114095 (patch)
treefc3933384d83187ea6b20f927582f20ff09ac3c3
parent4a5a4ddfc432f1fc569aa5a76b2b68ebb4b2062f (diff)
downloadpython-setuptools-git-2504699e5f9acfdd1438512173f90b3f61114095.tar.gz
Suppress AttributeError when detecting get-pip. Fixes #3002.
-rw-r--r--_distutils_hack/__init__.py12
-rw-r--r--changelog.d/3002.misc.rst1
2 files changed, 13 insertions, 0 deletions
diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
index 4745f8b9..75bc4463 100644
--- a/_distutils_hack/__init__.py
+++ b/_distutils_hack/__init__.py
@@ -73,6 +73,17 @@ def do_override():
ensure_local_distutils()
+class suppress(contextlib.suppress, contextlib.ContextDecorator):
+ """
+ A version of contextlib.suppress with decorator support.
+
+ >>> @suppress(KeyError)
+ ... def key_error():
+ ... {}['']
+ >>> key_error()
+ """
+
+
class DistutilsMetaFinder:
def find_spec(self, fullname, path, target=None):
if path is not None:
@@ -133,6 +144,7 @@ class DistutilsMetaFinder:
)
@classmethod
+ @suppress(AttributeError)
def is_get_pip(cls):
"""
Detect if get-pip is being invoked. Ref #2993.
diff --git a/changelog.d/3002.misc.rst b/changelog.d/3002.misc.rst
new file mode 100644
index 00000000..ed2c3936
--- /dev/null
+++ b/changelog.d/3002.misc.rst
@@ -0,0 +1 @@
+Suppress AttributeError when detecting get-pip.