Skip to content

Commit

Permalink
PEP-654: implement new formatting in traceback.py. Fix a whitespace i…
Browse files Browse the repository at this point in the history
…n c traceback (#1878)
  • Loading branch information
iritkatriel authored Mar 20, 2021
1 parent 89cb6aa commit 021015b
Showing 1 changed file with 62 additions and 46 deletions.
108 changes: 62 additions & 46 deletions pep-0654.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,36 @@ contains only those exceptions for which the condition is true:
... ]
... )
>>> traceback.print_exception(eg)
ExceptionGroup: one
------------------------------------------------------------
TypeError: 1
------------------------------------------------------------
ExceptionGroup: two
------------------------------------------------------------
TypeError: 2
------------------------------------------------------------
ValueError: 3
------------------------------------------------------------
ExceptionGroup: three
------------------------------------------------------------
OSError: 4
| ExceptionGroup: one
| with 3 sub-exceptions:
+-+---------------- 1 ----------------
| TypeError: 1
+---------------- 2 ----------------
| ExceptionGroup: two
| with 2 sub-exceptions:
+-+---------------- 2.1 ----------------
| TypeError: 2
+---------------- 2.2 ----------------
| ValueError: 3
+------------------------------------
+---------------- 3 ----------------
| ExceptionGroup: three
| with one sub-exception:
+-+---------------- 3.1 ----------------
| OSError: 4
+------------------------------------
>>> type_errors = eg.subgroup(lambda e: isinstance(e, TypeError))
>>> traceback.print_exception(type_errors)
ExceptionGroup: one
------------------------------------------------------------
TypeError: 1
------------------------------------------------------------
ExceptionGroup: two
------------------------------------------------------------
TypeError: 2
| ExceptionGroup: one
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| TypeError: 1
+---------------- 2 ----------------
| ExceptionGroup: two
| with one sub-exception:
+-+---------------- 2.1 ----------------
| TypeError: 2
+------------------------------------
>>>
Expand All @@ -227,23 +235,31 @@ If both the subgroup and its complement are needed, the
>>> type_errors, other_errors = eg.split(lambda e: isinstance(e, TypeError))
>>> traceback.print_exception(type_errors)
ExceptionGroup: one
------------------------------------------------------------
TypeError: 1
------------------------------------------------------------
ExceptionGroup: two
------------------------------------------------------------
TypeError: 2
| ExceptionGroup: one
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| TypeError: 1
+---------------- 2 ----------------
| ExceptionGroup: two
| with one sub-exception:
+-+---------------- 2.1 ----------------
| TypeError: 2
+------------------------------------
>>> traceback.print_exception(other_errors)
ExceptionGroup: one
------------------------------------------------------------
ExceptionGroup: two
------------------------------------------------------------
ValueError: 3
------------------------------------------------------------
ExceptionGroup: three
------------------------------------------------------------
OSError: 4
| ExceptionGroup: one
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| ExceptionGroup: two
| with one sub-exception:
+-+---------------- 1.1 ----------------
| ValueError: 3
+------------------------------------
+---------------- 2 ----------------
| ExceptionGroup: three
| with one sub-exception:
+-+---------------- 2.1 ----------------
| OSError: 4
+------------------------------------
>>>
Expand Down Expand Up @@ -381,7 +397,7 @@ in the following example:
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: one
| with one sub-exception:
| with one sub-exception:
+-+---------------- 2.1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 3, in f
Expand Down Expand Up @@ -839,7 +855,7 @@ it into the new ``ExceptionGroup``.
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: one
| with one sub-exception:
| with one sub-exception:
+-+---------------- 1.context.1 ----------------
| ValueError: a
+------------------------------------
Expand All @@ -859,7 +875,7 @@ it into the new ``ExceptionGroup``.
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: one
| with one sub-exception:
| with one sub-exception:
+-+---------------- 2.1 ----------------
| TypeError: b
+------------------------------------
Expand All @@ -881,10 +897,10 @@ chaining:
... raise ValueError('bad value') from e
...
| ExceptionGroup
| with one sub-exception:
| with one sub-exception:
+-+---------------- 1 ----------------
| ExceptionGroup
| with one sub-exception:
| with one sub-exception:
+-+---------------- 1.cause.1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
Expand Down Expand Up @@ -913,7 +929,7 @@ other clauses from the same ``try`` statement:
... print('never')
...
| ExceptionGroup
| with one sub-exception:
| with one sub-exception:
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 4, in <module>
Expand All @@ -936,12 +952,12 @@ direct child of the new exception group created for that:
... raise KeyError('x')
...
| ExceptionGroup
| with one sub-exception:
| with one sub-exception:
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: eg
| with one sub-exception:
| with one sub-exception:
+-+---------------- 1.context.1 ----------------
| ValueError: a
+------------------------------------
Expand All @@ -964,7 +980,7 @@ direct child of the new exception group created for that:
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: eg
| with one sub-exception:
| with one sub-exception:
+-+---------------- 1.context.1 ----------------
| ValueError: a
+------------------------------------
Expand All @@ -978,7 +994,7 @@ direct child of the new exception group created for that:
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: eg
| with one sub-exception:
| with one sub-exception:
+-+---------------- 2.1 ----------------
| TypeError: b
+------------------------------------
Expand Down

0 comments on commit 021015b

Please sign in to comment.