From 49c2a899dc2c1d5cb1cd0434632e58e262a3fc8e Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Fri, 5 Nov 2021 11:17:37 +0000 Subject: [PATCH] [PEP-654] update traceback formatting in examples --- pep-0654.rst | 124 ++++++++++++++++++++------------------------------- 1 file changed, 48 insertions(+), 76 deletions(-) diff --git a/pep-0654.rst b/pep-0654.rst index a7a547d817a..fe5de46cda3 100644 --- a/pep-0654.rst +++ b/pep-0654.rst @@ -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 "", line 1, in - | ExceptionGroup: two - | with 2 sub-exceptions: - +-+---------------- 1 ---------------- - | Traceback (most recent call last): - | File "", line 3, in f - | ValueError: 2 - +---------------- 2 ---------------- - | Traceback (most recent call last): - | File "", line 2, in - | ExceptionGroup: one - | with one sub-exception: - +-+---------------- 2.1 ---------------- - | Traceback (most recent call last): - | File "", line 3, in f - | ValueError: 1 - +------------------------------------ + + Exception Group Traceback (most recent call last): + | File "", line 1, in + | ExceptionGroup: two + +-+---------------- 1 ---------------- + | Traceback (most recent call last): + | File "", line 3, in f + | ValueError: 2 + +---------------- 2 ---------------- + | Exception Group Traceback (most recent call last): + | File "", line 2, in + | ExceptionGroup: one + +-+---------------- 1 ---------------- + | Traceback (most recent call last): + | File "", 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 "", line 15, in | File "", line 2, in | 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 "", line 2, in | 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 "", line 2, in | 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 "", line 4, in | 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 "", line 2, in | 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 "", line 2, in | 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 "", line 4, in @@ -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 "", line 2, in | 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 "", line 2, in | 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 "", line 4, in | KeyError: 'x' +---------------- 2 ---------------- - | Traceback (most recent call last): + | Exception Group Traceback (most recent call last): | File "", line 2, in | ExceptionGroup: eg - | with one sub-exception: - +-+---------------- 2.1 ---------------- + +-+---------------- 1 ---------------- | TypeError: b +------------------------------------ >>>