Permalink
Browse files

Now there aren't bare except: and it is explicit what exception is th…

…rown
  • Loading branch information...
1 parent 7e2f17a commit 5d95bb97d44622e2bba5d2cccad37699c981a1a3 tsmars15 committed Nov 28, 2011
@@ -86,10 +86,10 @@ while True:
try:
output = eval(line, _globals)
- except:
+ except SyntaxError:
try:
output = eval(compile(line, 'tm_sympy', 'exec'), _globals)
- except:
+ except (SyntaxError, TypeError) :
send("verbatim", traceback.format_exc(limit = 0))
continue
View
2 examples/all.py 100755 → 100644
@@ -133,7 +133,7 @@ def run_examples(windowed=False):
mod = load_example_module(example)
mod.main()
success.append(example)
- except:
+ except ImportError:
traceback.print_exc()
fail.append(example)
if success:
@@ -19,11 +19,11 @@ def sample2d(f, x_args):
"""
try:
f = sympify(f)
- except:
+ except SympifyError:
raise ValueError("f could not be interpretted as a SymPy function")
try:
x, x_min, x_max, x_n = x_args
- except:
+ except AttributeError:
raise ValueError("x_args must be a tuple of the form (var, min, max, n)")
x_l = float(x_max - x_min)
@@ -34,7 +34,7 @@ def sample2d(f, x_args):
for i in range(len(X)):
try:
Y[i] = float(f.subs(x, X[i]))
- except:
+ except TypeError:
Y[i] = None
return X, Y
@@ -51,12 +51,12 @@ def sample3d(f, x_args, y_args):
y, y_min, y_max, y_n = None, None, None, None
try:
f = sympify(f)
- except:
+ except SympifyError:
raise ValueError("f could not be interpreted as a SymPy function")
try:
x, x_min, x_max, x_n = x_args
y, y_min, y_max, y_n = y_args
- except:
+ except AttributeError:
raise ValueError("x_args and y_args must be tuples of the form (var, min, max, intervals)")
x_l = float(x_max - x_min)
@@ -88,7 +88,7 @@ def meshgrid(x, y):
for k in range(len(X[0])):
try:
Z[j][k] = float( f.subs(x, X[j][k]).subs(y, Y[j][k]) )
- except:
+ except (TypeError, NotImplementedError):
Z[j][k] = 0
return X, Y, Z
View
2 setup.py 100755 → 100644
@@ -105,7 +105,7 @@ def run(self):
import os
try:
import pyflakes.scripts.pyflakes as flakes
- except:
+ except ImportError:
print """In order to run the audit, you need to have PyFlakes installed."""
sys.exit(-1)
# We don't want to audit external dependencies
View
@@ -143,7 +143,7 @@ def __setstate__(self, d):
for name, value in d.iteritems():
try:
setattr(self, name, value)
- except:
+ except AttributeError:
pass
def compare(self, other):
View
@@ -1030,7 +1030,7 @@ def evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None,
try:
# If the result is numerical, normalize it
result = evalf(v, prec, options)
- except:
+ except NotImplementedError:
# Probably contains symbols or unknown functions
return v
re, im, re_acc, im_acc = result
@@ -1539,7 +1539,7 @@ def norm(self, ord=None):
# Note that while useful this is not mathematically a norm
try:
return Pow( Add(*(abs(i)**ord for i in self.mat)), S(1)/ord )
- except:
+ except TypeError:
raise ValueError("Expected order to be Number, Symbol, oo")
# Matrix Norms
View
@@ -110,7 +110,7 @@ def isnpint(ctx, x):
def convert(ctx, x):
try:
return float(x)
- except:
+ except TypeError:
return complex(x)
power = staticmethod(math2.pow)
@@ -166,7 +166,7 @@ def isint(ctx, z):
z = z.real
try:
return z == int(z)
- except:
+ except TypeError:
return False
def nint_distance(ctx, z):
View
@@ -108,7 +108,7 @@ def _compare(s, t, cmpfun):
if not hasattr(t, "_mpi_"):
try:
t = s.ctx.convert(t)
- except:
+ except (ValueError, TypeError):
return NotImplemented
return cmpfun(s._mpi_, t._mpi_)
@@ -192,7 +192,7 @@ def _compare(s, t, ne=False):
if not isinstance(t, s.ctx._types):
try:
t = s.ctx.convert(t)
- except:
+ except (ValueError, TypeError):
return NotImplemented
if hasattr(t, '_mpi_'):
tval = t._mpi_, mpi_zero
@@ -643,7 +643,7 @@ def _hurwitz_reflection(ctx, s, a, d, atype):
if atype == 'Q' or atype == 'Z':
try:
p, q = a._mpq_
- except:
+ except AttributeError:
assert a == int(a)
p = int(a)
q = 1
@@ -64,7 +64,7 @@
if gmpy.version() >= '1.03':
BACKEND = 'gmpy'
MPZ = gmpy.mpz
- except:
+ except ImportError:
pass
if 'MPMATH_NOSAGE' not in os.environ:
@@ -75,7 +75,7 @@
sage_utils = _sage_utils
BACKEND = 'sage'
MPZ = sage.Integer
- except:
+ except ImportError:
pass
if 'MPMATH_STRICT' in os.environ:
@@ -418,7 +418,7 @@ def from_float(x, prec=53, rnd=round_fast):
# in Python2.6 it returns (float infinity, 0)
try:
m, e = math.frexp(x)
- except:
+ except FloatingPointError:
if x == math_float_inf: return finf
if x == -math_float_inf: return fninf
return fnan
@@ -15,7 +15,7 @@ def check(name, func, z, y):
global errcount
try:
x = func(z)
- except:
+ except NotImplementedError:
errcount += 1
if raise_:
raise
@@ -124,7 +124,7 @@ def testit(importdir='', testdir=''):
t1 = clock()
try:
module.__dict__[f]()
- except:
+ except (KeyboardInterrupt, SystemExit, AttributeError):
etype, evalue, trb = sys.exc_info()
if etype in (KeyboardInterrupt, SystemExit):
raise
@@ -117,7 +117,7 @@ def test_jtheta():
raised = True
try:
r = jtheta(n, z, q)
- except:
+ except ValueError:
pass
else:
raised = False
@@ -927,7 +927,7 @@ def _rot(axis, angle):
u2 = expand(td[u2])
u3 = expand(td[u3])
wvec = u1 * self.x + u2 * self.y + u3 * self.z
- except:
+ except (ImportError, TypeError ):
wvec = self._w_diff_dcm(parent)
self._ang_vel_dict.update({parent: wvec})
parent._ang_vel_dict.update({self: -wvec})
@@ -1937,7 +1937,7 @@ def dynamicsymbols(names, level=0):
ol.append(diff(v, dynamicsymbols._t))
esses = ol
return list(ol)
- except:
+ except TypeError:
esses = esses.__call__(dynamicsymbols._t)
for i in range(level):
esses = diff(esses, dynamicsymbols._t)
@@ -119,7 +119,7 @@ def eval(cls, arg):
"""
try:
d = arg._dagger_()
- except:
+ except AttributeError:
if isinstance(arg, Basic):
if arg.is_Add:
return Add(*tuple(map(Dagger, arg.args)))
@@ -80,14 +80,14 @@ def _interpret_args(self, args, kwargs):
fv = atoms[0]
try:
f = lambdify(s, [fv, fv, fv])
- except:
+ except TypeError:
raise f_error
elif len(atoms) == 3:
fr, fg, fb = atoms
try:
f = lambdify(s, [fr, fg, fb])
- except:
+ except TypeError:
raise f_error
else:
@@ -104,7 +104,7 @@ def _interpret_args(self, args, kwargs):
elif len(lists) == 2:
try:
(r1, g1, b1), (r2, g2, b2) = lists
- except:
+ except TypeError:
raise ValueError("If two color arguments are given, "
"they must be given in the format "
"(r1, g1, b1), (r2, g2, b2).")
@@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs):
stride = kwargs.pop('stride', 0.25)
try:
stride = eval(stride)
- except:
+ except TypeError:
pass
if is_sequence(stride):
assert len(stride) == 3
@@ -38,13 +38,13 @@ def set_rot_preset(self, preset_name):
self.init_rot_matrix()
try:
r = self.rot_presets[preset_name]
- except:
+ except AttributeError:
raise ValueError("%s is not a valid rotation preset." % preset_name)
try:
self.euler_rotate(r[0], 1, 0, 0)
self.euler_rotate(r[1], 0, 1, 0)
self.euler_rotate(r[2], 0, 0, 1)
- except:
+ except AttributeError:
pass
def reset(self):
@@ -22,7 +22,7 @@ def _on_calculate_verts(self):
for t in self.t_set:
try:
_e = evaluate(t) # calculate vertex
- except:
+ except (NameError, ZeroDivisionError):
_e = None
if _e is not None: # update bounding box
for axis in xrange(3):
@@ -21,7 +21,7 @@ def __init__(self, *args):
elif isinstance(args[0], str):
try:
args = eval(args[0])
- except:
+ except TypeError:
s_eval_error = "Could not interpret string %s."
raise ValueError(s_eval_error % (args[0]))
elif isinstance(args[0], (tuple, list)):
@@ -63,7 +63,7 @@ def set_v_min(self, v_min):
try:
self._v_min = sympify(v_min)
float(self._v_min.evalf())
- except:
+ except TypeError:
raise ValueError("v_min could not be interpreted as a number.")
def get_v_max(self):
@@ -75,7 +75,7 @@ def set_v_max(self, v_max):
try:
self._v_max = sympify(v_max)
float(self._v_max.evalf())
- except:
+ except TypeError:
raise ValueError("v_max could not be interpreted as a number.")
def get_v_steps(self):
@@ -123,7 +123,7 @@ def try_parse(*args):
return args[0]
try:
return PlotInterval(*args)
- except:
+ except ValueError:
return None
def _str_base(self):
@@ -121,7 +121,7 @@ def _get_mode(mode_arg, i_var_count, d_var_count):
m = None
if issubclass(mode_arg, PlotMode):
m = mode_arg
- except:
+ except TypeError:
pass
if m:
if not m._was_initialized:
@@ -165,7 +165,7 @@ def _get_default_mode(i, d, i_vars=-1):
i_vars = i
try:
return PlotMode._mode_default_map[d][i]
- except:
+ except TypeError:
# Keep looking for modes in higher i var counts
# which support the given d var count until we
# reach the max i_var count.
@@ -186,7 +186,7 @@ def _get_aliased_mode(alias, i, d, i_vars=-1):
% (alias, ", ".join(PlotMode._mode_alias_list)))
try:
return PlotMode._mode_map[d][i][alias]
- except:
+ except TypeError:
# Keep looking for modes in higher i var counts
# which support the given d var count and alias
# until we reach the max i_var count.
@@ -372,7 +372,7 @@ def _interpret_args(args):
try:
f = sympify(a)
functions.append(f)
- except:
+ except TypeError:
raise ValueError(interpret_error % str(a))
return functions, intervals
@@ -27,7 +27,7 @@ def _on_calculate_verts(self):
for v in self.v_set:
try:
_e = evaluate(u, v) # calculate vertex
- except:
+ except ZeroDivisionError:
_e = None
if _e is not None: # update bounding box
for axis in xrange(3):
@@ -107,7 +107,7 @@ def draw(self):
if r.calculating_cverts:
calc_cverts_pos += r.calculating_cverts_pos
calc_cverts_len += r.calculating_cverts_len
- except:
+ except ValueError:
pass
for r in self.plot._pobjects:
@@ -5,14 +5,14 @@
ctypes_major = int(ctypes.__version__.split('.')[0])
if ctypes_major < 1:
disabled = True
-except:
+except ImportError:
disabled = True
try:
# if pyglet.gl fails to import, e.g. opengl is missing, we disable the tests
import pyglet.gl
import pyglet.window
-except:
+except ImportError:
disabled = True
from sympy import symbols, sin, cos
Oops, something went wrong.

0 comments on commit 5d95bb9

Please sign in to comment.