summaryrefslogtreecommitdiffstats
path: root/Lib/contextlib.py
diff options
context:
space:
mode:
authorƁukasz Langa <lukasz@langa.pl>2023-04-24 22:17:02 (GMT)
committerGitHub <noreply@github.com>2023-04-24 22:17:02 (GMT)
commit22bed58e531ce780d91f3364c5ace98fad28c2e8 (patch)
tree09719c749f02573ed8f47cb5f682651596f008e8 /Lib/contextlib.py
parent19e4f757de8c7cf2b4b9b4cbb32e376d0e50d2d4 (diff)
downloadcpython-22bed58e531ce780d91f3364c5ace98fad28c2e8.zip
cpython-22bed58e531ce780d91f3364c5ace98fad28c2e8.tar.gz
cpython-22bed58e531ce780d91f3364c5ace98fad28c2e8.tar.bz2
gh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup (#103792)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r--Lib/contextlib.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index 30d9ac2..b5acbcb 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -441,7 +441,16 @@ class suppress(AbstractContextManager):
# exactly reproduce the limitations of the CPython interpreter.
#
# See http://bugs.python.org/issue12029 for more details
- return exctype is not None and issubclass(exctype, self._exceptions)
+ if exctype is None:
+ return
+ if issubclass(exctype, self._exceptions):
+ return True
+ if issubclass(exctype, ExceptionGroup):
+ match, rest = excinst.split(self._exceptions)
+ if rest is None:
+ return True
+ raise rest
+ return False
class _BaseExitStack: