Closed nirit100 closed 3 months ago
excellent, thank you!
I just tested on cpy3.11, none of __notes__
, __cause__
, __traceback__
are copied by BaseExceptionGroup.derive
there:
>>> eg = ExceptionGroup("abc", [TypeError()])
>>> raise eg
+ Exception Group Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| ExceptionGroup: abc (1 sub-exception)
+-+---------------- 1 ----------------
| TypeError
+------------------------------------
>>> eg.__traceback__
<traceback object at 0x7f8f21dae5c0>
>>> eg.derive([TypeError()]).__traceback__
>>> eg.add_note('hello')
>>> eg
ExceptionGroup('abc', [TypeError()])
>>> raise eg
+ Exception Group Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| File "<stdin>", line 1, in <module>
| ExceptionGroup: abc (1 sub-exception)
| hello
+-+---------------- 1 ----------------
| TypeError
+------------------------------------
>>> eg.derive([TypeError()]).__notes__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ExceptionGroup' object has no attribute '__notes__'. Did you mean: '__ne__'?
>>>
here's the source code of derive: https://github.com/python/cpython/blob/3.11/Objects/exceptions.c#L880
and of subset: https://github.com/python/cpython/blob/3.11/Objects/exceptions.c#L920
Only implemented the
BaseExceptionGroup
andExceptionGroup
classes. No integration rn.Based on this implementation: ExceptionGroup backport
Also, there are still one FIXME and two TODOs:
test_notes_is_list_of_strings_if_it_exists
is marked asxfail
right now becauseadd_note
is not available yet__notes__
over in thederive
function__cause__
,__context__
and__traceback__
is fine to be done inderive
, because unlike__notes__
that was done on the caller side in the referenced implementation.