--- examples/advanced/gibbs_phenomenon.py | 2 +- sympy/core/basic.py | 4 ++-- sympy/core/function.py | 2 +- sympy/core/numbers.py | 2 +- sympy/core/power.py | 4 ++-- sympy/geometry/ellipse.py | 2 +- sympy/geometry/point.py | 2 +- sympy/physics/secondquant.py | 2 +- sympy/plotting/plot_interval.py | 2 +- sympy/plotting/plot_mode.py | 4 ++-- sympy/plotting/plot_mode_base.py | 4 ++-- sympy/printing/printer.py | 6 +++--- sympy/printing/python.py | 2 +- sympy/solvers/solvers.py | 2 +- sympy/test_external/test_numpy.py | 2 +- sympy/utilities/compilef.py | 2 +- sympy/utilities/pytest.py | 2 +- sympy/utilities/tests/test_lambdify.py | 22 +++++++++++----------- sympy/utilities/tests/test_pytest.py | 6 ++++-- 19 files changed, 38 insertions(+), 36 deletions(-)
diff --git a/examples/advanced/gibbs_phenomenon.py b/examples/advanced/gibbs_phenomenon.py index e12a074..1aaf4ce 100755 --- a/examples/advanced/gibbs_phenomenon.py +++ b/examples/advanced/gibbs_phenomenon.py @@ -67,7 +67,7 @@ def l2_gram_schmidt(list, lim): v = a - l2_projection(a, r, lim) v_norm = l2_norm(v, lim) if v_norm == 0: - raise Exception("The sequence is not linearly independent.") + raise ValueError("The sequence is not linearly independent.") r.append(v/v_norm) return r diff --git a/sympy/core/basic.py b/sympy/core/basic.py index 5a2de01..f17a46c 100644 --- a/sympy/core/basic.py +++ b/sympy/core/basic.py @@ -381,7 +381,7 @@ class Basic(AssumeMeths): # new-style classes + __getattr__ is *very* slow! # def __getattr__(self, name): - # raise Exception('no way, *all* attribute access will be 2.5x slower') + # raise Warning('no way, *all* attribute access will be 2.5x slower') # here is what we do instead: for k in AssumeMeths._assume_defined: @@ -929,7 +929,7 @@ class Basic(AssumeMeths): old, new = args return self._subs_old_new(old, new) else: - raise Exception("subs accept either 1 or 2 arguments") + raise TypeError("subs accepts either 1 or 2 arguments") @cacheit def _subs_old_new(self, old, new): diff --git a/sympy/core/function.py b/sympy/core/function.py index 3242a53..ecf4fce 100644 --- a/sympy/core/function.py +++ b/sympy/core/function.py @@ -125,7 +125,7 @@ class Function(Basic): else: print args print type(args[0]) - raise Exception("You need to specify exactly one string") + raise TypeError("You need to specify exactly one string") # (2) create new instance of a class created in (1) # UC: Function('f')(x) diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py index f9cc5f2..e9061e1 100644 --- a/sympy/core/numbers.py +++ b/sympy/core/numbers.py @@ -504,7 +504,7 @@ class Rational(Number): if q==0: if p==0: if _errdict["divide"]: - raise Exception("Indeterminate 0/0") + raise ValueError("Indeterminate 0/0") else: return S.NaN if p<0: return S.NegativeInfinity diff --git a/sympy/core/power.py b/sympy/core/power.py index a7f487b..d19e343 100644 --- a/sympy/core/power.py +++ b/sympy/core/power.py @@ -499,7 +499,7 @@ class Pow(Basic): if n.is_Pow: return n.args[1] - raise Exception("Unimplemented") + raise NotImplementedError() base, exp = self.args if exp.is_Integer: @@ -558,7 +558,7 @@ class Pow(Basic): elif l.is_number and l>0: l = float(l) else: - raise Exception("Not implemented") + raise NotImplementedError() s = 1 m = 1 diff --git a/sympy/geometry/ellipse.py b/sympy/geometry/ellipse.py index 3dd6cb8..c112220 100644 --- a/sympy/geometry/ellipse.py +++ b/sympy/geometry/ellipse.py @@ -91,7 +91,7 @@ class Ellipse(GeometryEntity): hr, vr = self.hradius, self.vradius if hr.atoms(C.Symbol) or vr.atoms(C.Symbol): - raise Exception("foci can only be determined on non-symbolic radii") + raise ValueError("foci can only be determined on non-symbolic radii") v = sqrt(abs(vr**2 - hr**2)) if hr < vr: diff --git a/sympy/geometry/point.py b/sympy/geometry/point.py index 2574917..2815d35 100644 --- a/sympy/geometry/point.py +++ b/sympy/geometry/point.py @@ -203,7 +203,7 @@ class Point(GeometryEntity): if len(other) == len(self): return Point( [simplify(a+b) for a,b in zip(self, other)] ) else: - raise Exception("Points must have the same number of dimensions") + raise TypeError("Points must have the same number of dimensions") else: other = sympify(other) return Point( [simplify(a+other) for a in self] ) diff --git a/sympy/physics/secondquant.py b/sympy/physics/secondquant.py index e226c81..3f5d819 100644 --- a/sympy/physics/secondquant.py +++ b/sympy/physics/secondquant.py @@ -546,7 +546,7 @@ class FixedBosonicBasis(BosonicBasis): # elif isinstance(e, Add): # a, b = e.as_two_terms() # return move(a, i, d) + move(b, i, d) -# raise Exception("Not implemented.") +# raise NotImplementedError() def commutator(a, b): """ diff --git a/sympy/plotting/plot_interval.py b/sympy/plotting/plot_interval.py index 3191daf..beca69d 100644 --- a/sympy/plotting/plot_interval.py +++ b/sympy/plotting/plot_interval.py @@ -8,7 +8,7 @@ class PlotInterval(object): def require_all_args(f): def check(self, *args, **kwargs): for g in [self._v, self._v_min, self._v_max, self._v_steps]: - if g is None: raise Exception("PlotInterval is incomplete.") + if g is None: raise ValueError("PlotInterval is incomplete.") return f(self, *args, **kwargs) return check diff --git a/sympy/plotting/plot_mode.py b/sympy/plotting/plot_mode.py index a87a29d..ebbecee 100644 --- a/sympy/plotting/plot_mode.py +++ b/sympy/plotting/plot_mode.py @@ -206,7 +206,7 @@ class PlotMode(PlotObject): cls._init_mode() #except Exception, e: - # raise Exception( ("Failed to initialize " + # raise RuntimeError( ("Failed to initialize " # "plot mode %s. Reason: %s") # % (name, (str(e))) ) @@ -228,7 +228,7 @@ class PlotMode(PlotObject): PlotMode._mode_default_map[d][i] = cls except Exception, e: - raise Exception( ("Failed to register " + raise RuntimeError( ("Failed to register " "plot mode %s. Reason: %s") % (name, (str(e))) ) diff --git a/sympy/plotting/plot_mode_base.py b/sympy/plotting/plot_mode_base.py index 6af950c..8657364 100644 --- a/sympy/plotting/plot_mode_base.py +++ b/sympy/plotting/plot_mode_base.py @@ -311,7 +311,7 @@ class PlotModeBase(PlotMode): if v == self._style: return self._style = v #except Exception, e: - #raise Exception(("Style change failed. " + #raise RuntimeError(("Style change failed. " #"Reason: %s is not a valid " #"style. Use one of %s.") % #(str(v), ', '.join(self.styles.iterkeys()))) @@ -330,7 +330,7 @@ class PlotModeBase(PlotMode): self._on_change_color(v) self._color = v except Exception, e: - raise Exception(("Color change failed. " + raise RuntimeError(("Color change failed. " "Reason: %s" % (str(e)))) style = property(_get_style, _set_style) diff --git a/sympy/printing/printer.py b/sympy/printing/printer.py index a92c663..587b44a 100644 --- a/sympy/printing/printer.py +++ b/sympy/printing/printer.py @@ -137,7 +137,7 @@ class Printer(object): if self.printmethod and hasattr(expr, self.printmethod): res = getattr(expr, self.printmethod)() if res is None: - raise Exception("Printing method '%s' of an instance of '%s' did return None" %\ + raise RuntimeError("Printing method '%s' of an instance of '%s' did return None" %\ (self.printmethod, expr.__class__.__name__)) return res @@ -148,14 +148,14 @@ class Printer(object): if hasattr(self, printmethod): res = getattr(self, printmethod)(expr, *args) if res is None: - raise Exception("Printing method '%s' did return None"%\ + raise RuntimeError("Printing method '%s' did return None"%\ printmethod) return res # Unknown object, fall back to the emptyPrinter. res = self.emptyPrinter(expr) if res is None: - raise Exception("emptyPrinter method of '%s' did return None" %\ + raise RuntimeError("emptyPrinter method of '%s' did return None" %\ self.__class__.__name__) return res finally: diff --git a/sympy/printing/python.py b/sympy/printing/python.py index 5d10442..a6757c4 100644 --- a/sympy/printing/python.py +++ b/sympy/printing/python.py @@ -38,7 +38,7 @@ class PythonPrinter(ReprPrinter, StrPrinter): return StrPrinter._print_Symbol(self, expr) def _print_module(self, expr): - raise Exception('Modules in the expression are unacceptable') + raise ValueError('Modules in the expression are unacceptable') def python(expr): diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py index d7e900a..45ab16d 100644 --- a/sympy/solvers/solvers.py +++ b/sympy/solvers/solvers.py @@ -244,7 +244,7 @@ def solve(f, *symbols, **flags): # b!=0. result = tsolve(f, *symbols) elif strategy == -1: - raise Exception('Could not parse expression %s' % f) + raise ValueError('Could not parse expression %s' % f) else: raise NotImplementedError("No algorithms are implemented to solve equation %s" % f) diff --git a/sympy/test_external/test_numpy.py b/sympy/test_external/test_numpy.py index fd3ad78..0c127ce 100644 --- a/sympy/test_external/test_numpy.py +++ b/sympy/test_external/test_numpy.py @@ -196,7 +196,7 @@ def test_lambdify(): assert -prec < f(0.2) - sin02 < prec try: f(x) # if this succeeds, it can't be a numpy function - raise Exception + assert False except AttributeError: pass diff --git a/sympy/utilities/compilef.py b/sympy/utilities/compilef.py index 8fd5f03..d2f6250 100644 --- a/sympy/utilities/compilef.py +++ b/sympy/utilities/compilef.py @@ -226,7 +226,7 @@ def __run(cmd): Checks the exit code of a ran command. """ if not cmd == 0: - raise Exception('could not run libtcc command') + raise RuntimeError('could not run libtcc command') def _compile(code, argcount=None, fname='f', fprototype=None): """ diff --git a/sympy/utilities/pytest.py b/sympy/utilities/pytest.py index 4975815..25ed9f7 100644 --- a/sympy/utilities/pytest.py +++ b/sympy/utilities/pytest.py @@ -22,7 +22,7 @@ def raises(ExpectedException, code): exec code in frame.f_globals, loc except ExpectedException: return - raise Exception("DID NOT RAISE") + raise AssertionError("DID NOT RAISE") if not USE_PYTEST: class XFail(Exception): diff --git a/sympy/utilities/tests/test_lambdify.py b/sympy/utilities/tests/test_lambdify.py index 533a4e6..49f396b 100644 --- a/sympy/utilities/tests/test_lambdify.py +++ b/sympy/utilities/tests/test_lambdify.py @@ -15,7 +15,7 @@ def test_no_args(): f = lambdify([], 1) try: f(-1) - raise Exception() + assert False except TypeError: pass assert f() == 1 @@ -35,7 +35,7 @@ def test_str_args(): # make sure correct number of args required try: f(0) - raise Exception() + assert False except TypeError: pass @@ -51,7 +51,7 @@ def test_own_module(): f = lambdify(x, sympy.ceiling(x), math) try: f(4.5) - raise Exception + assert False except NameError: pass @@ -59,13 +59,13 @@ def test_bad_args(): try: # no vargs given f = lambdify(1) - raise Exception() + assert False except TypeError: pass try: # same with vector exprs f = lambdify([1,2]) - raise Exception() + assert False except TypeError: pass @@ -78,7 +78,7 @@ def test_sympy_lambda(): try: # arctan is in numpy module and should not be available f = lambdify(x, arctan(x), "sympy") - raise Exception + assert False except NameError: pass @@ -88,7 +88,7 @@ def test_math_lambda(): assert -prec < f(0.2) - sin02 < prec try: f(x) # if this succeeds, it can't be a python math function - raise Exception + assert False except ValueError: pass @@ -98,7 +98,7 @@ def test_mpmath_lambda(): assert -prec < f(mpmath.mpf("0.2")) - sin02 < prec try: f(x) # if this succeeds, it can't be a mpmath function - raise Exception + assert False except TypeError: pass @@ -143,7 +143,7 @@ def test_sqrt(): assert f(6.25) == 2.5 try: f(-1) - raise Exception() + assert False except ValueError: pass def test_trig(): @@ -165,14 +165,14 @@ def test_vector_simple(): # make sure correct number of args required try: f(0) - raise Exception() + assert False except TypeError: pass def test_vector_discontinuous(): f = lambdify(x, (-1/x, 1/x)) try: f(0) - raise Exception() + assert False except ZeroDivisionError: pass assert f(1) == (-1.0, 1.0) assert f(2) == (-0.5, 0.5) diff --git a/sympy/utilities/tests/test_pytest.py b/sympy/utilities/tests/test_pytest.py index 6148ac3..0a4c209 100644 --- a/sympy/utilities/tests/test_pytest.py +++ b/sympy/utilities/tests/test_pytest.py @@ -3,6 +3,8 @@ from sympy.utilities.pytest import raises def test_raises(): class My(Exception): pass + class My2(Exception): + pass raises(My, "raise My()") try: @@ -12,7 +14,7 @@ def test_raises(): assert str(e) == "DID NOT RAISE" try: - raises(My, "raise Exception('my text123')") + raises(My, "raise My2('my text123')") assert False - except Exception, e: + except My2, e: assert str(e) == "my text123" -- 1.5.6.5 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to sympy-patches+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---