Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now there aren't bare except: and it is explicit what exception is thrown #784

Closed
wants to merge 11 commits into from
4 changes: 2 additions & 2 deletions data/TeXmacs/bin/tm_sympy
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/all.py 100755 → 100644
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions examples/intermediate/sample.py
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py 100755 → 100644
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/basic.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/evalf.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sympy/matrices/matrices.py
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions sympy/physics/mechanics/essential.py
Expand Up @@ -916,6 +916,7 @@ def _rot(axis, angle):
wvec = thetad * amounts[1].express(parent).normalize()
else:
try:
from sympy.polys.polyerrors import CoercionFailed
from sympy.physics.mechanics.functions import kinematic_equations
q1, q2, q3 = amounts
u1, u2, u3 = dynamicsymbols('u1, u2, u3')
Expand All @@ -927,7 +928,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 (CoercionFailed, AssertionError):
wvec = self._w_diff_dcm(parent)
self._ang_vel_dict.update({parent: wvec})
parent._ang_vel_dict.update({self: -wvec})
Expand Down Expand Up @@ -1937,7 +1938,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)
Expand Down
2 changes: 1 addition & 1 deletion sympy/physics/secondquant.py
Expand Up @@ -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)))
Expand Down
6 changes: 3 additions & 3 deletions sympy/plotting/color_scheme.py
Expand Up @@ -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:
Expand All @@ -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).")
Expand Down
2 changes: 1 addition & 1 deletion sympy/plotting/plot_axes.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sympy/plotting/plot_camera.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion sympy/plotting/plot_curve.py
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions sympy/plotting/plot_interval.py
Expand Up @@ -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)):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -123,7 +123,7 @@ def try_parse(*args):
return args[0]
try:
return PlotInterval(*args)
except:
except ValueError:
return None

def _str_base(self):
Expand Down
8 changes: 4 additions & 4 deletions sympy/plotting/plot_mode.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sympy/plotting/plot_surface.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion sympy/plotting/plot_window.py
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions sympy/plotting/tests/test_plotting.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sympy/plotting/textplot.py
Expand Up @@ -23,7 +23,7 @@ def textplot(expr, a, b, W=55, H=18):
for x in range(W):
try:
y[x] = f(a+(b-a)/float(W)*x)
except:
except TypeError:
y[x] = 0

# Normalize height to screen space
Expand Down
2 changes: 1 addition & 1 deletion sympy/plotting/util.py
Expand Up @@ -121,7 +121,7 @@ def strided_range(r_min, r_max, stride, max_steps=50):
return []
try:
xrange(int(r_min-r_max))
except:
except TypeError:
return []
assert r_min < r_max
r_min_s = (r_min % stride)
Expand Down
2 changes: 1 addition & 1 deletion sympy/printing/latex.py
Expand Up @@ -930,7 +930,7 @@ def _print_FiniteSet(self, s):
printset = s
try:
printset.sort()
except:
except AttributeError:
pass
return r"\left\{" + r", ".join(self._print(el) for el in printset) + r"\right\}"
def _print_Interval(self, i):
Expand Down
2 changes: 1 addition & 1 deletion sympy/printing/pretty/pretty.py
Expand Up @@ -1078,7 +1078,7 @@ def _print_FiniteSet(self, s):
printset = s
try:
printset = sorted(printset)
except: pass
except AttributeError: pass

return self._print_seq(printset, '{', '}', ', ' )

Expand Down
2 changes: 1 addition & 1 deletion sympy/printing/str.py
Expand Up @@ -122,7 +122,7 @@ def _print_FiniteSet(self, s):
printset = s
try:
printset = sorted(printset)
except: pass
except AttributeError: pass
return '{' + ', '.join(self._print(el) for el in printset) + '}'

def _print_Function(self, expr):
Expand Down
2 changes: 1 addition & 1 deletion sympy/solvers/solvers.py
Expand Up @@ -222,7 +222,7 @@ def checksol(f, symbol, sol=None, **flags):
return False
try:
nz = val.is_nonzero
except: # any problem at all: recursion, inconsistency of facts, etc...
except Exception: # any problem at all: recursion, inconsistency of facts, etc...
nz = None
if nz is not None:
if val.is_number and val.has(LambertW): # issue 2574: it may be True even when False
Expand Down
2 changes: 1 addition & 1 deletion sympy/solvers/tests/test_solvers.py
Expand Up @@ -28,7 +28,7 @@ def guess_solve_strategy(eq, symbol):
try:
solve(eq, symbol)
return True
except:
except (TypeError, NotImplementedError):
return False

def test_guess_poly():
Expand Down
2 changes: 1 addition & 1 deletion sympy/utilities/pytest.py
Expand Up @@ -142,7 +142,7 @@ def func_wrapper():
func()
except Outcome:
raise # pass-through test outcome
except:
except XFail(Exception):
raise XFail(func.func_name)
else:
raise XPass(func.func_name)
Expand Down