mirror of https://github.com/python/cpython
bpo-46107: ExceptionGroup.subgroup()/split() should copy __note__ to the parts (GH-30159)
This commit is contained in:
parent
e9a01e231a
commit
c66fc0fb53
|
@ -495,13 +495,14 @@ class ExceptionGroupSplitTestBase(ExceptionGroupTestBase):
|
|||
match and e in match_leaves,
|
||||
rest and e in rest_leaves)
|
||||
|
||||
# message, cause and context equal to eg
|
||||
# message, cause and context, traceback and note equal to eg
|
||||
for part in [match, rest, sg]:
|
||||
if part is not None:
|
||||
self.assertEqual(eg.message, part.message)
|
||||
self.assertIs(eg.__cause__, part.__cause__)
|
||||
self.assertIs(eg.__context__, part.__context__)
|
||||
self.assertIs(eg.__traceback__, part.__traceback__)
|
||||
self.assertIs(eg.__note__, part.__note__)
|
||||
|
||||
def tbs_for_leaf(leaf, eg):
|
||||
for e, tbs in leaf_generator(eg):
|
||||
|
@ -566,6 +567,7 @@ class NestedExceptionGroupSplitTest(ExceptionGroupSplitTestBase):
|
|||
try:
|
||||
nested_group()
|
||||
except ExceptionGroup as e:
|
||||
e.__note__ = f"the note: {id(e)}"
|
||||
eg = e
|
||||
|
||||
eg_template = [
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix bug where :meth:`ExceptionGroup.split` and :meth:`ExceptionGroup.subgroup` did not copy the exception group's ``__note__`` field to the parts.
|
|
@ -901,6 +901,11 @@ exceptiongroup_subset(
|
|||
}
|
||||
PyException_SetContext(eg, PyException_GetContext(orig));
|
||||
PyException_SetCause(eg, PyException_GetCause(orig));
|
||||
|
||||
PyObject *note = _PyBaseExceptionObject_cast(orig)->note;
|
||||
Py_XINCREF(note);
|
||||
_PyBaseExceptionObject_cast(eg)->note = note;
|
||||
|
||||
*result = eg;
|
||||
return 0;
|
||||
error:
|
||||
|
|
Loading…
Reference in New Issue