From afddc54054ce3c30c68f60e4b9985bb478908a84 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Wed, 9 Jan 2019 17:44:55 -0600 Subject: Add note that explain() is only supported under Python 3. --- pyparsing.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'pyparsing.py') diff --git a/pyparsing.py b/pyparsing.py index fd7c0fa..ab804d5 100644 --- a/pyparsing.py +++ b/pyparsing.py @@ -333,6 +333,8 @@ class ParseException(ParseBaseException): that failed to parse. These representations will be more helpful if you use `setName` to give identifiable names to your expressions. Otherwise they will use the default string forms, which may be cryptic to read. + + explain() is only supported under Python 3. """ import inspect @@ -344,15 +346,9 @@ class ParseException(ParseBaseException): ret.append(' ' * (exc.col - 1) + '^') ret.append("{0}: {1}".format(type(exc).__name__, exc)) - 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: + callers = inspect.getinnerframes(exc.__traceback__, context=depth) + seen = set() for i, ff in enumerate(callers[-depth:]): frm = ff.frame -- cgit v1.2.1