Skip to content

Commit

Permalink
Trac #18799: Python 3 preparation: Change syntax of raise with traceback
Browse files Browse the repository at this point in the history
{{{2to3}}} proposes changes for
{{{
raise E, V, T -> raise E(V).with_traceback(T)
raise E, None, T -> raise E.with_traceback(T)
}}}
These changes are invalid (see also #18796).

Several options are given in the documentation of python-future (see
http://python-future.org/compatible_idioms.html#raising-exceptions).

This ticket is tracked as a dependency of meta-ticket #16052.
The simple {{{raise}}} statements are fixed in #15990.

URL: http://trac.sagemath.org/18799
Reported by: wluebbe
Ticket author(s): Wilfried Luebbe
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager authored and vbraun committed Oct 18, 2015
2 parents a73dbeb + 249b939 commit 7ade658
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/sage/interfaces/expect.py
Expand Up @@ -67,6 +67,8 @@
from sage.env import SAGE_EXTCODE, LOCAL_IDENTIFIER
from sage.misc.object_multiplexer import Multiplex

from six import reraise as raise_

BAD_SESSION = -2

# The subprocess is a shared resource. In a multi-threaded
Expand Down Expand Up @@ -883,7 +885,7 @@ def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if
except (TypeError, RuntimeError):
pass
return self._eval_line(line,allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt, restart_if_needed=False)
raise RuntimeError, "%s\nError evaluating %s in %s"%(msg, line, self), sys.exc_info()[2]
raise_(RuntimeError, "%s\nError evaluating %s in %s"%(msg, line, self), sys.exc_info()[2])

if len(line)>0:
try:
Expand Down Expand Up @@ -1329,7 +1331,7 @@ def __init__(self, parent, value, is_name=False, name=None):
# coercion to work properly.
except (RuntimeError, ValueError) as x:
self._session_number = -1
raise TypeError, x, sys.exc_info()[2]
raise_(TypeError, x, sys.exc_info()[2])
except BaseException:
self._session_number = -1
raise
Expand Down
4 changes: 3 additions & 1 deletion src/sage/interfaces/singular.py
Expand Up @@ -334,6 +334,8 @@
from sage.misc.misc import get_verbose
from sage.misc.superseded import deprecation

from six import reraise as raise_

class SingularError(RuntimeError):
"""
Raised if Singular printed an error message
Expand Down Expand Up @@ -1261,7 +1263,7 @@ def __init__(self, parent, type, value, is_name=False):
# coercion to work properly.
except SingularError as x:
self._session_number = -1
raise TypeError, x, sys.exc_info()[2]
raise_(TypeError, x, sys.exc_info()[2])
except BaseException:
self._session_number = -1
raise
Expand Down
4 changes: 3 additions & 1 deletion src/sage/schemes/elliptic_curves/ell_number_field.py
Expand Up @@ -109,6 +109,8 @@

import gal_reps_number_field

from six import reraise as raise_

class EllipticCurve_number_field(EllipticCurve_field):
r"""
Elliptic curve over a number field.
Expand Down Expand Up @@ -893,7 +895,7 @@ def _reduce_model(self):
(a1, a2, a3, a4, a6) = [ZK(a) for a in self.a_invariants()]
except TypeError:
import sys
raise TypeError, "_reduce_model() requires an integral model.", sys.exc_info()[2]
raise_(TypeError, "_reduce_model() requires an integral model.", sys.exc_info()[2])

# N.B. Must define s, r, t in the right order.
if ZK.absolute_degree() == 1:
Expand Down

0 comments on commit 7ade658

Please sign in to comment.