From ccd0d5249fbbf5a413a819f5c4f17d9f51e6e766 Mon Sep 17 00:00:00 2001
From: Irit Katriel <iritkatriel@yahoo.com>
Date: Fri, 19 Mar 2021 19:07:48 +0000
Subject: [PATCH] PEP-654: implement new formatting in traceback.py. Fix a
 whitespace in c traceback

---
 pep-0654.rst | 108 +++++++++++++++++++++++++++++----------------------
 1 file changed, 62 insertions(+), 46 deletions(-)

diff --git a/pep-0654.rst b/pep-0654.rst
index d9e7b60baed..7209d325e8e 100644
--- a/pep-0654.rst
+++ b/pep-0654.rst
@@ -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
+         +------------------------------------
    >>>
 
 
@@ -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
+         +------------------------------------
    >>>
 
 
@@ -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
@@ -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
           +------------------------------------
@@ -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
           +------------------------------------
@@ -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>
@@ -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>
@@ -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
          +------------------------------------
@@ -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
          +------------------------------------
@@ -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
          +------------------------------------