From 17aeb190d87186e769ddea8752099d841421faab Mon Sep 17 00:00:00 2001 From: ptmcg Date: Wed, 9 Jan 2019 17:27:33 -0600 Subject: Modify explain() for Py2 compat --- pyparsing.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pyparsing.py') diff --git a/pyparsing.py b/pyparsing.py index d6f016d..fd7c0fa 100644 --- a/pyparsing.py +++ b/pyparsing.py @@ -94,7 +94,7 @@ classes inherit from. Use the docstrings for examples of how to: """ __version__ = "2.3.1" -__versionTime__ = "09 Jan 2019 23:17 UTC" +__versionTime__ = "09 Jan 2019 23:26 UTC" __author__ = "Paul McGuire " import string @@ -344,7 +344,12 @@ class ParseException(ParseBaseException): ret.append(' ' * (exc.col - 1) + '^') ret.append("{0}: {1}".format(type(exc).__name__, exc)) - callers = inspect.getinnerframes(exc.__traceback__, context=depth) + if hasattr(exc, '__traceback__'): + exc_tb = exc.__traceback__ + else: + exc_tb = sys.exc_info()[-1] + callers = inspect.getinnerframes(exc_tb, context=depth) + seen = set() if depth > 0: -- cgit v1.2.1