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:
parent
22114c7ba3
commit
afa1503545
|
@ -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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue