bpo-45292: [PEP 654] Update traceback display code to work with exception groups by iritkatriel · Pull Request #29207 · python/cpython
Do you have an opinion on whether it's better to box all EG tracebacks or only the nested ones?
I think it's OK to always box the EGs because they're pretty special, although I'd change the very first line of the output, from:
| Traceback (most recent call last):
| File "{__file__}", line {exc.__code__.co_firstlineno + 9}, in exc
| raise EG("eg", [VE(1), exc, VE(4)])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ExceptionGroup: eg
+-+---------------- context.1 ----------------
| ValueError: 1
+---------------- context.2 ----------------
| Traceback (most recent call last):
| File "{__file__}", line {exc.__code__.co_firstlineno + 6}, in exc
| raise EG("nested", [TE(2), TE(3)])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ExceptionGroup: nested
+-+---------------- context.2.1 ----------------
| TypeError: 2
+---------------- context.2.2 ----------------
| TypeError: 3
+------------------------------------
+---------------- context.3 ----------------
| ValueError: 4
+------------------------------------
to:
+ Exception group traceback (most recent call last):
|
| File "{__file__}", line {exc.__code__.co_firstlineno + 9}, in exc
| raise EG("eg", [VE(1), exc, VE(4)])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ExceptionGroup: eg
+-+---------------- context.1 ----------------
| ValueError: 1
+---------------- context.2 ----------------
| Traceback (most recent call last):
| File "{__file__}", line {exc.__code__.co_firstlineno + 6}, in exc
| raise EG("nested", [TE(2), TE(3)])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ExceptionGroup: nested
+-+---------------- context.2.1 ----------------
| TypeError: 2
+---------------- context.2.2 ----------------
| TypeError: 3
+------------------------------------
+---------------- context.3 ----------------
| ValueError: 4
+------------------------------------