Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fix bare "except:" statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Mar 8, 2019
1 parent c59b688 commit 367b0a1
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/sage/graphs/connectivity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ def spqr_tree(G, algorithm="Hopcroft_Tarjan", solver=None, verbose=0):
try:
if block[1].has_edge(e):
Tree.add_edge(block, P_block)
except:
except LookupError:
continue
if num == 2:
# When 2 S or R blocks are separated by a 2-cut without edge, we
Expand All @@ -2439,7 +2439,7 @@ def spqr_tree(G, algorithm="Hopcroft_Tarjan", solver=None, verbose=0):
if block[1].has_edge(e):
Tree.add_edge(block, P_block)
break
except:
except LookupError:
continue

return Tree
Expand Down
18 changes: 12 additions & 6 deletions src/sage/groups/matrix_gps/orthogonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ def _OG(n, R, special, e=0, var='a', invariant_form=None):
if not invariant_form.is_symmetric():
raise ValueError("invariant_form must be symmetric")

inserted_text = 'with respect to symmetrc form'
try:
if not invariant_form.is_positive_definite():
inserted_text = 'with respect to non positive definite symmetrc form'
except:
pass
if invariant_form.is_positive_definite():
inserted_text = "with respect to positive definite symmetric form"
else:
inserted_text = "with respect to non positive definite symmetric form"
except ValueError:
inserted_text = "with respect to symmetric form"

name = '{0} Orthogonal Group of degree {1} over {2} {3}\n{4}'.format(
prefix, degree, ring, inserted_text,invariant_form)
Expand Down Expand Up @@ -295,6 +296,11 @@ def GO(n, R, e=0, var='a', invariant_form=None):
NotImplementedError: invariant_form for finite groups is fixed by GAP
sage: 5+5
10
sage: R.<x> = ZZ[]
sage: GO(2, R, invariant_form=[[x,0],[0,1]])
General Orthogonal Group of degree 2 over Univariate Polynomial Ring in x over Integer Ring with respect to symmetric form
[x 0]
[0 1]
TESTS::
Expand Down Expand Up @@ -441,7 +447,7 @@ class OrthogonalMatrixGroup_generic(NamedMatrixGroup_generic):
sage: m=matrix(CF3, 3,3, [[1,e3,0],[e3,2,0],[0,0,1]])
sage: G = SO(3, CF3, invariant_form=m)
sage: latex(G)
\text{SO}_{3}(\Bold{Q}(\zeta_{3}))\text{ with respect to non positive definite symmetrc form }\left(\begin{array}{rrr}
\text{SO}_{3}(\Bold{Q}(\zeta_{3}))\text{ with respect to non positive definite symmetric form }\left(\begin{array}{rrr}
1 & \zeta_{3} & 0 \\
\zeta_{3} & 2 & 0 \\
0 & 0 & 1
Expand Down
15 changes: 8 additions & 7 deletions src/sage/groups/matrix_gps/unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,16 @@ def _UG(n, R, special, var='a', invariant_form=None):
if not invariant_form.is_hermitian():
raise ValueError("invariant_form must be hermitian")

inserted_text = 'with respect to hermitian form'
try:
if not invariant_form.is_positive_definite():
inserted_text = 'with respect to non positive definite hermitian form'
except:
pass
if invariant_form.is_positive_definite():
inserted_text = "with respect to positive definite hermitian form"
else:
inserted_text = "with respect to non positive definite hermitian form"
except ValueError:
inserted_text = "with respect to hermitian form"

name = '{0} Unitary Group of degree {1} over {2} {3}\n{4}'.format(prefix,
degree, ring, inserted_text,invariant_form)
degree, ring, inserted_text, invariant_form)
ltx = r'\text{{{0}U}}_{{{1}}}({2})\text{{ {3} }}{4}'.format(latex_prefix,
degree, latex(ring), inserted_text, latex(invariant_form))
else:
Expand Down Expand Up @@ -375,7 +376,7 @@ class UnitaryMatrixGroup_generic(NamedMatrixGroup_generic):
sage: m=matrix(CF3, 3,3, [[1,e3,0],[e3.conjugate(),2,0],[0,0,1]])
sage: G = SU(3, CF3, invariant_form=m)
sage: latex(G)
\text{SU}_{3}(\Bold{Q}(\zeta_{3}))\text{ with respect to hermitian form }\left(\begin{array}{rrr}
\text{SU}_{3}(\Bold{Q}(\zeta_{3}))\text{ with respect to positive definite hermitian form }\left(\begin{array}{rrr}
1 & \zeta_{3} & 0 \\
-\zeta_{3} - 1 & 2 & 0 \\
0 & 0 & 1
Expand Down
5 changes: 3 additions & 2 deletions src/sage/manifolds/calculus_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,17 @@ def _Sympy_to_SR(expression):
"""
try:
return SR(expression)
except:
except Exception:
# If SR cannot transform a sympy expression is because it is a
# sympy abstract function.
a = expression._sage_()
# As all sage objects have a ._sage_ operator, they have to be
# catched
if type(a) == type(expression):
if type(a) is type(expression):
raise TypeError
return a


class CalculusMethod(SageObject):
r"""
Control of calculus methods used on coordinate charts of manifolds.
Expand Down
8 changes: 3 additions & 5 deletions src/sage/modules/free_quadratic_module_integer_symmetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,9 @@ def IntegralLatticeGluing(Lattices, glue, return_embeddings=False):
for i in range(N):
ALi = Lattices[i].discriminant_group()
for g in glue:
try:
ALi(g[i])
except:
raise ValueError("the gluing vectors must be in the"
"corresponding discriminant groups")
# Check that the gluing vectors are in the
# corresponding discriminant groups
ALi(g[i])
generators = [sum(phi[i](g[i].lift()*g[i].order())/g[i].order()
for i in range(N))
for g in glue]
Expand Down
7 changes: 2 additions & 5 deletions src/sage/rings/valuation/valuation_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,10 +1031,7 @@ def inverse(self, x, precision):
1/2
"""
try:
return x.inverse_of_unit()
except:
raise NotImplementedError("can not compute approximate inverse with respect to this valuation")
return x.inverse_of_unit()

def _relative_size(self, x):
r"""
Expand Down Expand Up @@ -1636,7 +1633,7 @@ def _test_inverse(self, **options):
for prec in (0, 1, 42, infinity):
try:
y = self.inverse(x, prec)
except NotImplementedError:
except ArithmeticError: # Inverse does not exist
continue
except ValueError:
if prec is not infinity:
Expand Down
6 changes: 4 additions & 2 deletions src/sage/schemes/projective/projective_rational_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,11 @@ def parallel_function_combination(point_p_max):
continue

try:
rat_points.add(X(list(A[1]))) # checks if this point lies on X or not
except:
pt = X(list(A[1]))
except TypeError:
pass
else:
rat_points.add(pt)

return [list(_) for _ in rat_points]

Expand Down
14 changes: 7 additions & 7 deletions src/sage/schemes/projective/projective_subscheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"""

#*****************************************************************************
# Copyright (C) 2005 William Stein <wstein@gmail.com>
# Copyright (C) 2013 Ben Hutz <bn4941@gmail.com>

# Copyright (C) 2005 William Stein <wstein@gmail.com>
# Copyright (C) 2013 Ben Hutz <bn4941@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# https://www.gnu.org/licenses/
#*****************************************************************************

from sage.arith.misc import binomial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
sage: try:
....: p.solve()
....: print("The problem has a solution!")
....: except:
....: except RuntimeError:
....: print("The problem is infeasible!")
The problem is infeasible!
Expand Down

0 comments on commit 367b0a1

Please sign in to comment.