Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP-654: implement new formatting in traceback.py. Fix a whitespace i… #1878

Merged
merged 1 commit into from
Mar 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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