From 22bed58e531ce780d91f3364c5ace98fad28c2e8 Mon Sep 17 00:00:00 2001 From: Ɓukasz Langa Date: Tue, 25 Apr 2023 00:17:02 +0200 Subject: gh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup (#103792) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- Lib/contextlib.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Lib/contextlib.py') diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 30d9ac25b2b..b5acbcb9e6d 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: -- cgit v1.2.3