Skip to content

Commit fa991ad

Browse files
remove ExceptionGroup if the exception needed to remove in ExceptionGroup.exceptions
1 parent 160b47c commit fa991ad

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Lib/traceback.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,30 @@ def _remove_exception(exc_value, other_exc_value, _seen=None):
204204
_seen = set()
205205
if id(exc_value) not in _seen:
206206
_seen.add(id(exc_value))
207-
if exc_value.__cause__:
207+
if isinstance(exc_value.__cause__, BaseException):
208208
if exc_value.__cause__ is other_exc_value:
209209
exc_value.__cause__ = None
210+
elif isinstance(exc_value.__cause__, BaseExceptionGroup):
211+
if other_exc_value in exc_value.__cause__.exceptions:
212+
exc_value.__cause__ = None
213+
else:
214+
_remove_exception(exc_value.__cause__, other_exc_value, _seen)
215+
for i in exc_value.__cause__.exceptions:
216+
_remove_exception(i, other_exc_value, _seen)
210217
else:
211218
_remove_exception(exc_value.__cause__, other_exc_value, _seen)
212-
if exc_value.__context__:
219+
if isinstance(exc_value.__context__, BaseException):
213220
if exc_value.__context__ is other_exc_value:
214221
exc_value.__context__ = None
222+
elif isinstance(exc_value.__context__, BaseExceptionGroup):
223+
if other_exc_value in exc_value.__context__.exceptions:
224+
exc_value.__context__ = None
225+
else:
226+
_remove_exception(
227+
exc_value.__context__, other_exc_value, _seen
228+
)
229+
for i in exc_value.__context__.exceptions:
230+
_remove_exception(i, other_exc_value, _seen)
215231
else:
216232
_remove_exception(
217233
exc_value.__context__, other_exc_value, _seen

0 commit comments

Comments
 (0)