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] update traceback formatting in examples #2133

Merged
merged 1 commit into from
Nov 5, 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
124 changes: 48 additions & 76 deletions pep-0654.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,33 +186,29 @@ contains only those exceptions for which the condition is true:
... )
>>> traceback.print_exception(eg)
| ExceptionGroup: one
| with 3 sub-exceptions:
+-+---------------- 1 ----------------
| TypeError: 1
+---------------- 2 ----------------
| ExceptionGroup: two
| with 2 sub-exceptions:
+-+---------------- 2.1 ----------------
+-+---------------- 1 ----------------
| TypeError: 2
+---------------- 2.2 ----------------
+---------------- 2 ----------------
| ValueError: 3
+------------------------------------
+---------------- 3 ----------------
| ExceptionGroup: three
| with one sub-exception:
+-+---------------- 3.1 ----------------
+-+---------------- 1 ----------------
| OSError: 4
+------------------------------------

>>> type_errors = eg.subgroup(lambda e: isinstance(e, TypeError))
>>> traceback.print_exception(type_errors)
| ExceptionGroup: one
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| TypeError: 1
+---------------- 2 ----------------
| ExceptionGroup: two
| with one sub-exception:
+-+---------------- 2.1 ----------------
+-+---------------- 1 ----------------
| TypeError: 2
+------------------------------------
>>>
Expand Down Expand Up @@ -243,28 +239,23 @@ 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
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| TypeError: 1
+---------------- 2 ----------------
| ExceptionGroup: two
| with one sub-exception:
+-+---------------- 2.1 ----------------
+-+---------------- 1 ----------------
| TypeError: 2
+------------------------------------
>>> traceback.print_exception(other_errors)
| ExceptionGroup: one
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| ExceptionGroup: two
| with one sub-exception:
+-+---------------- 1.1 ----------------
+-+---------------- 1 ----------------
| ValueError: 3
+------------------------------------
+---------------- 2 ----------------
| ExceptionGroup: three
| with one sub-exception:
+-+---------------- 2.1 ----------------
+-+---------------- 1 ----------------
| OSError: 4
+------------------------------------
>>>
Expand Down Expand Up @@ -392,24 +383,22 @@ in the following example:
... eg = e
...
>>> raise ExceptionGroup("two", [f(2), eg])
| Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| ExceptionGroup: two
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 3, in f
| ValueError: 2
+---------------- 2 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: one
| with one sub-exception:
+-+---------------- 2.1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 3, in f
| ValueError: 1
+------------------------------------
+ Exception Group Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| ExceptionGroup: two
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 3, in f
| ValueError: 2
+---------------- 2 ----------------
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: one
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 3, in f
| ValueError: 1
+------------------------------------
>>>

Handling Exception Groups
Expand Down Expand Up @@ -812,36 +801,31 @@ merged with the unhandled ``TypeErrors``.
*ValueError: ExceptionGroup('eg', [ValueError(1), ExceptionGroup('nested', [ValueError(6)])])
*OSError: ExceptionGroup('eg', [OSError(3), ExceptionGroup('nested', [OSError(4)])])
| ExceptionGroup
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 15, in <module>
| File "<stdin>", line 2, in <module>
| ExceptionGroup: eg
| with 2 sub-exceptions:
+-+---------------- 1.1 ----------------
+-+---------------- 1 ----------------
| ValueError: 1
+---------------- 1.2 ----------------
+---------------- 2 ----------------
| ExceptionGroup: nested
| with one sub-exception:
+-+---------------- 1.2.1 ----------------
+-+---------------- 1 ----------------
| ValueError: 6
+------------------------------------
+---------------- 2 ----------------
| Traceback (most recent call last):
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: eg
| with 3 sub-exceptions:
+-+---------------- 2.1 ----------------
+-+---------------- 1 ----------------
| TypeError: 2
+---------------- 2.2 ----------------
+---------------- 2 ----------------
| OSError: 3
+---------------- 2.3 ----------------
+---------------- 3 ----------------
| ExceptionGroup: nested
| with 2 sub-exceptions:
+-+---------------- 2.3.1 ----------------
+-+---------------- 1 ----------------
| OSError: 4
+---------------- 2.3.2 ----------------
+---------------- 2 ----------------
| TypeError: 5
+------------------------------------
>>>
Expand All @@ -863,33 +847,29 @@ it into the new ``ExceptionGroup``.
... raise ExceptionGroup("two", [KeyError('x'), KeyError('y')])
...
| ExceptionGroup
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: one
| with one sub-exception:
+-+---------------- 1.context.1 ----------------
+-+---------------- 1 ----------------
| ValueError: a
+------------------------------------
|
| During handling of the above exception, another exception occurred:
|
| Traceback (most recent call last):
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 4, in <module>
| ExceptionGroup: two
| with 2 sub-exceptions:
+-+---------------- 1.1 ----------------
+-+---------------- 1 ----------------
| KeyError: 'x'
+---------------- 1.2 ----------------
+---------------- 2 ----------------
| KeyError: 'y'
+------------------------------------
+---------------- 2 ----------------
| Traceback (most recent call last):
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: one
| with one sub-exception:
+-+---------------- 2.1 ----------------
+-+---------------- 1 ----------------
| TypeError: b
+------------------------------------
>>>
Expand All @@ -910,11 +890,9 @@ chaining:
... raise ValueError('bad value') from e
...
| ExceptionGroup
| with one sub-exception:
+-+---------------- 1 ----------------
| ExceptionGroup
| with one sub-exception:
+-+---------------- 1.cause.1 ----------------
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| TypeError: bad type
Expand Down Expand Up @@ -942,7 +920,6 @@ other clauses from the same ``try`` statement:
... print('never')
...
| ExceptionGroup
| with one sub-exception:
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 4, in <module>
Expand All @@ -965,13 +942,11 @@ direct child of the new exception group created for that:
... raise KeyError('x')
...
| ExceptionGroup
| with one sub-exception:
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: eg
| with one sub-exception:
+-+---------------- 1.context.1 ----------------
+-+---------------- 1 ----------------
| ValueError: a
+------------------------------------
|
Expand All @@ -988,13 +963,11 @@ direct child of the new exception group created for that:
... raise KeyError('x')
...
| ExceptionGroup
| with 2 sub-exceptions:
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: eg
| with one sub-exception:
+-+---------------- 1.context.1 ----------------
+-+---------------- 1 ----------------
| ValueError: a
+------------------------------------
|
Expand All @@ -1004,11 +977,10 @@ direct child of the new exception group created for that:
| File "<stdin>", line 4, in <module>
| KeyError: 'x'
+---------------- 2 ----------------
| Traceback (most recent call last):
| Exception Group Traceback (most recent call last):
| File "<stdin>", line 2, in <module>
| ExceptionGroup: eg
| with one sub-exception:
+-+---------------- 2.1 ----------------
+-+---------------- 1 ----------------
| TypeError: b
+------------------------------------
>>>
Expand Down