mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup (#103792)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
19e4f757de
commit
22bed58e53
6 changed files with 73 additions and 22 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue