PEP-654: simplify traverse() example (#1844)

We don't need to pass the cause and context from the root. The ones for the leaf are on the leaf exception itself.
This commit is contained in:
Irit Katriel 2021-02-26 22:20:35 +00:00 committed by GitHub
parent 22114c7ba3
commit afa1503545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 5 deletions

View File

@ -330,20 +330,18 @@ calling ``traverse(eg)``, where ``traverse`` is defined as follows:
.. code-block::
def traverse(exc, tbs=None, cause=None, context=None):
def traverse(exc, tbs=None):
if tbs is None:
tbs = []
cause = exc.__cause__
context = exc.__context__
tbs.append(exc.__traceback__)
if isinstance(exc, ExceptionGroup):
for e in exc.errors:
traverse(e, tbs, cause, context)
traverse(e, tbs)
else:
# exc is a leaf exception and its traceback
# is the concatenation of the traceback in tbs
process_leaf(exc, tbs, cause, context)
process_leaf(exc, tbs)
tbs.pop()