[PEP-654] update traceback formatting in examples (GH-2133)

This commit is contained in:
Irit Katriel 2021-11-05 14:45:24 +00:00 committed by GitHub
parent 0098f08851
commit 026d74bde7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 76 deletions

View File

@ -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
+------------------------------------
>>>
@ -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
+------------------------------------
>>>
@ -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
@ -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
+------------------------------------
>>>
@ -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
+------------------------------------
>>>
@ -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
@ -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>
@ -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
+------------------------------------
|
@ -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
+------------------------------------
|
@ -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
+------------------------------------
>>>