[py3k] Fix raise with embedded traceback
authorRémi Cardona <remi.cardona@free.fr>
Sun, 20 Jul 2014 12:52:15 +0200
changeset 744 f66ac8ee424e
parent 743 75496cdceeae
child 745 8e53b305c77b
[py3k] Fix raise with embedded traceback python 3 removed the raise syntax with 3 expressions.
__init__.py
--- a/__init__.py	Wed Jul 23 08:30:38 2014 +0200
+++ b/__init__.py	Sun Jul 20 12:52:15 2014 +0200
@@ -227,7 +227,9 @@
                 msg = '%s\nat: %r\n%s' % (rqlstring, ex.pos,  ex.msg)
             else:
                 msg = '%s\n%s' % (rqlstring, ex.msg)
-            raise RQLSyntaxError(msg), None, sys.exc_info()[-1]
+            exc = RQLSyntaxError(msg)
+            exc.__traceback__ = sys.exc_info()[-1]
+            raise exc
         # try to get error message from yapps
         try:
             out = sys.stdout
@@ -236,13 +238,19 @@
                 print_error(ex, parser._scanner)
             finally:
                 sys.stdout = out
-            raise RQLSyntaxError(stream.getvalue()), None, sys.exc_info()[-1]
+            exc = RQLSyntaxError(stream.getvalue())
+            exc.__traceback__ = sys.exc_info()[-1]
+            raise exc
         except ImportError: # duh?
             sys.stdout = out
-            raise RQLSyntaxError('Syntax Error', ex.msg, 'on line',
-                                 1 + pinput.count('\n', 0, ex.pos)), None, sys.exc_info()[-1]
+            exc = RQLSyntaxError('Syntax Error', ex.msg, 'on line',
+                                 1 + pinput.count('\n', 0, ex.pos))
+            exc.__traceback__ = sys.exc_info()[-1]
+            raise exc
     except NoMoreTokens:
         msg = 'Could not complete parsing; stopped around here: \n%s'
-        raise RQLSyntaxError(msg  % parser._scanner), None, sys.exc_info()[-1]
+        exc = RQLSyntaxError(msg  % parser._scanner)
+        exc.__traceback__ = sys.exc_info()[-1]
+        raise exc
 
 pyparse = parse