Skip to content

Commit

Permalink
Add back traceback._iter_chain for python 3.5+
Browse files Browse the repository at this point in the history
  • Loading branch information
felixonmars committed Nov 7, 2015
1 parent 070c482 commit 00463f1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/zope/testrunner/tb_format.py
Expand Up @@ -20,6 +20,31 @@
import zope.testrunner.feature


# Python 3.5 compatibility
if not hasattr(traceback, "_iter_chain"):
def _iter_chain(exc, custom_tb=None, seen=None):
if seen is None:
seen = set()
seen.add(exc)
its = []
cause = exc.__cause__
if cause is not None and cause not in seen:
its.append(_iter_chain(cause, None, seen))
its.append([(traceback._cause_message, None)])
else:
context = exc.__context__
if context is not None and context not in seen:
its.append(_iter_chain(context, None, seen))
its.append([(traceback._context_message, None)])
its.append([(exc, custom_tb or exc.__traceback__)])
# itertools.chain is in an extension module and may be unavailable
for it in its:
for x in it:
yield x

traceback._iter_chain = _iter_chain


def format_exception(t, v, tb, limit=None, chain=None):
if chain:
values = traceback._iter_chain(v, tb)
Expand Down

0 comments on commit 00463f1

Please sign in to comment.