Skip to content

Commit

Permalink
Py2 exceptions need special checks for presence of __traceback__
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmcg committed Mar 7, 2020
1 parent 7daecd9 commit 281b031
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pyparsing.py
Expand Up @@ -1950,7 +1950,8 @@ def parseString(self, instring, parseAll=False):
raise
else:
# catch and re-raise exception from here, clearing out pyparsing internal stack trace
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
if getattr(exc, '__traceback__', None) is not None:
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
raise exc
else:
return tokens
Expand Down Expand Up @@ -2025,7 +2026,8 @@ def scanString(self, instring, maxMatches=_MAX_INT, overlap=False):
raise
else:
# catch and re-raise exception from here, clearing out pyparsing internal stack trace
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
if getattr(exc, '__traceback__', None) is not None:
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
raise exc

def transformString(self, instring):
Expand Down Expand Up @@ -2072,7 +2074,8 @@ def transformString(self, instring):
raise
else:
# catch and re-raise exception from here, clearing out pyparsing internal stack trace
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
if getattr(exc, '__traceback__', None) is not None:
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
raise exc

def searchString(self, instring, maxMatches=_MAX_INT):
Expand Down Expand Up @@ -2103,7 +2106,8 @@ def searchString(self, instring, maxMatches=_MAX_INT):
raise
else:
# catch and re-raise exception from here, clearing out pyparsing internal stack trace
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
if getattr(exc, '__traceback__', None) is not None:
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
raise exc

def split(self, instring, maxsplit=_MAX_INT, includeSeparators=False):
Expand Down Expand Up @@ -2576,7 +2580,8 @@ def parseFile(self, file_or_filename, parseAll=False):
raise
else:
# catch and re-raise exception from here, clearing out pyparsing internal stack trace
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
if getattr(exc, '__traceback__', None) is not None:
exc.__traceback__ = self._trim_traceback(exc.__traceback__)
raise exc

def __eq__(self, other):
Expand Down

0 comments on commit 281b031

Please sign in to comment.