Skip to content

Commit

Permalink
sagemathgh-38788: Ruff e713
Browse files Browse the repository at this point in the history
Using ruff to auto-fix all E713 codes

Test for membership should be `not in`

then activating this check in the linter

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

URL: sagemath#38788
Reported by: Frédéric Chapoton
Reviewer(s): Vincent Macri
  • Loading branch information
Release Manager committed Oct 10, 2024
2 parents 3483150 + 181e960 commit 4dcda50
Show file tree
Hide file tree
Showing 36 changed files with 70 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .github/sync_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def actor_valid(self):
for com in coms:
for auth in com['authors']:
login = auth['login']
if not login in authors:
if login not in authors:
if not self.is_this_bot(login) and login != author:
debug('PR %s has recent commit by %s' % (self._issue, login))
authors.append(login)
Expand Down Expand Up @@ -746,7 +746,7 @@ def add_label(self, label):
r"""
Add the given label to the issue or PR.
"""
if not label in self.get_labels():
if label not in self.get_labels():
self.edit(label, '--add-label')
info('Add label to %s: %s' % (self._issue, label))

Expand Down
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=140d921780212198287a0d626b8c9655d4408f7a
sha256=4f82ec8bdb67c4dffd43daddd5160e8f9c624f6a5cf16c4128bfab2e5ddca459
sha1=70467c0efc0269f41bb620ec4dab17ca4b66bf23
sha256=6f4649eca09e31d7c5e0e60cd5a2b5b1b9759991e300c255dd768fb02fbefbdf
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2b4fe39e420df022d34a67fbc820252618e15f83
48c2d9c25d22fbb36725d2d4aa8305538dd21654
2 changes: 1 addition & 1 deletion src/sage/coding/gabidulin_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def __init__(self, base_field, length, dimension, sub_field=None,
if not len(evaluation_points) == length:
raise ValueError("the number of evaluation points should be equal to the length of the code")
for i in range(length):
if not evaluation_points[i] in base_field:
if evaluation_points[i] not in base_field:
raise ValueError("evaluation point does not belong to the 'base field'")
basis = self.matrix_form_of_vector(vector(evaluation_points))
if basis.rank() != length:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def BM_all_minimal(vp, return_transformation=False, D=None):
for M in all_M:
new_map = mp.conjugate(M)
new_map.normalize_coordinates()
if not [new_map, M] in all_maps:
if [new_map, M] not in all_maps:
all_maps.append([new_map, M])

#Split into conjugacy classes
Expand Down
12 changes: 6 additions & 6 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2935,7 +2935,7 @@ def parallel_function(morphism):
# Calling possible_periods for each prime in parallel
parallel_data = []
for q in primes(primebound[0], primebound[1] + 1):
if not (q in badprimes):
if q not in badprimes:
F = self.change_ring(GF(q))
parallel_data.append(((F,), {}))

Expand Down Expand Up @@ -6768,7 +6768,7 @@ def is_Lattes(self):
(crit_set, post_crit_set) = crit, list(post_crit)

# All Lattes maps have 3 or 4 post critical values
if not len(post_crit_set) in [3, 4]:
if len(post_crit_set) not in [3, 4]:
return False

f = F_crit.dehomogenize(1)[0]
Expand Down Expand Up @@ -7228,7 +7228,7 @@ def lift_to_rational_periodic(self, points_modp, B=None):
while not done and k <= n:
newP = self(newP)
if newP == P:
if not ([P, k] in good_points):
if [P, k] not in good_points:
good_points.append([newP, k])
done = True
k += 1
Expand Down Expand Up @@ -7499,7 +7499,7 @@ def all_periodic_points(self, **kwds):
pos_points = []
# check period, remove duplicates
for i in range(len(all_points)):
if all_points[i][1] in periods and not (all_points[i] in pos_points):
if all_points[i][1] in periods and all_points[i] not in pos_points:
pos_points.append(all_points[i])
periodic_points = DS.lift_to_rational_periodic(pos_points,B)
for p,n in periodic_points:
Expand Down Expand Up @@ -7594,7 +7594,7 @@ def all_rational_preimages(self, points):
P = points.pop()
preimages = self.rational_preimages(P)
for i in range(len(preimages)):
if not preimages[i] in preperiodic:
if preimages[i] not in preperiodic:
points.append(preimages[i])
preperiodic.add(preimages[i])
return list(preperiodic)
Expand Down Expand Up @@ -9073,7 +9073,7 @@ def is_newton(self, return_conjugation=False):
"""
if self.degree() == 1:
raise NotImplementedError("degree one Newton maps are trivial")
if not self.base_ring() in NumberFields():
if self.base_ring() not in NumberFields():
raise NotImplementedError("only implemented over number fields")
# check if Newton map
sigma_1 = self.sigma_invariants(1)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ def Bessel(*args, **kwds):
_type = kwds['typ']
else:
_type = 'J'
if not (_type in ['I', 'J', 'K', 'Y']):
if _type not in ['I', 'J', 'K', 'Y']:
raise ValueError("type must be one of I, J, K, Y")

# return the function
Expand Down
6 changes: 3 additions & 3 deletions src/sage/games/hexad.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,15 @@ def find_hexad3(self, pts, x0, x1):
L = set(pts)
H = {x0, x1}
for i in range(18):
if (not (MINIMOG[0][2] in H) and L <= picture_set(self.picture21, self.square[i])):
if (MINIMOG[0][2] not in H and L <= picture_set(self.picture21, self.square[i])):
WHAT = ["square " + str(i), "picture " + str(MINIMOG[0][2])]
H = H | picture_set(self.picture21, self.square[i])
return list(H), WHAT
if (not (MINIMOG[2][1] in H) and L <= picture_set(self.picture02, self.square[i])):
if (MINIMOG[2][1] not in H and L <= picture_set(self.picture02, self.square[i])):
WHAT = ["square " + str(i), "picture " + str(MINIMOG[2][1])]
H = H | picture_set(self.picture02, self.square[i])
return list(H), WHAT
if (not (MINIMOG[0][0] in H) and L <= picture_set(self.picture00, self.square[i])):
if (MINIMOG[0][0] not in H and L <= picture_set(self.picture00, self.square[i])):
WHAT = ["square " + str(i), "picture " + str(MINIMOG[0][0])]
H = H | picture_set(self.picture00, self.square[i])
return list(H), WHAT
Expand Down
6 changes: 3 additions & 3 deletions src/sage/geometry/hyperplane_arrangement/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ def plot(hyperplane_arrangement, **kwds):
if 'ranges' in kwds:
ranges_set = True
ranges = kwds.pop('ranges')
if not type(ranges) in [list,tuple]: # ranges is a single number
if type(ranges) not in [list,tuple]: # ranges is a single number
ranges = [ranges] * N
# So ranges is some type of list.
elif dim == 2: # arrangement of lines in the plane
if not type(ranges[0]) in [list,tuple]: # a single interval
if type(ranges[0]) not in [list,tuple]: # a single interval
ranges = [ranges] * N
elif dim == 3: # arrangement of planes in 3-space
if not type(ranges[0][0]) in [list,tuple]:
if type(ranges[0][0]) not in [list,tuple]:
ranges = [ranges] * N
elif dim not in [2,3]: # ranges is not an option unless dim is 2 or 3
ranges_set = False
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedron/base5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2452,7 +2452,7 @@ def _test_lawrence(self, tester=None, **options):
if tester is None:
tester = self._tester(**options)

if self.backend() == 'normaliz' and not self.base_ring() in (ZZ, QQ):
if self.backend() == 'normaliz' and self.base_ring() not in (ZZ, QQ):
# Speeds up the doctest for significantly.
self = self.change_ring(self._internal_base_ring)

Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/digraph_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ def RandomDirectedGNM(self, n, m, loops=False):
if is_dense:
for u in range(n):
for v in range(n):
if ((u != v) or loops) and (not (v in adj[u])):
if ((u != v) or loops) and (v not in adj[u]):
D.add_edge(u, v)

return D
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/generators/classical_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ def T2starGeneralizedQuadrangleGraph(q, dual=False, hyperoval=None, field=None,
raise RuntimeError("incorrect hyperoval size")
for L in Theta.blocks():
if set(L).issubset(Pi):
if not len(HO.intersection(L)) in [0, 2]:
if len(HO.intersection(L)) not in [0, 2]:
raise RuntimeError("incorrect hyperoval")

L = [[y for y in z if y not in HO]
Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18928,7 +18928,7 @@ def breadth_first_search(self, start, ignore_direction=False,
# Non-existing start vertex is detected later if distance > 0.
if not distance:
for v in queue:
if not v[0] in self:
if v[0] not in self:
raise LookupError("start vertex ({0}) is not a vertex of the graph".format(v[0]))

for v, d in queue:
Expand Down Expand Up @@ -22678,7 +22678,7 @@ def graphviz_string(self, **options):
for f in edge_option_functions:
edge_options.update(f((u, v, label)))

if not edge_options['edge_string'] in ['--', '->']:
if edge_options['edge_string'] not in ['--', '->']:
raise ValueError("edge_string(='{}') in edge_options dict for "
"the edge ({}, {}) should be '--' or '->'"
.format(edge_options['edge_string'], u, v))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/graph_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ def set_option(self, option_name, option_value=None):
raise TypeError('%s option must be a dictionary, not %s' % (name, value))
else:
for key, x in value.items():
if not type(x) in [int, Integer, float, RealLiteral] or not x >= 0.0:
if type(x) not in [int, Integer, float, RealLiteral] or not x >= 0.0:
raise ValueError('%s option for %s needs to be a positive number, not %s' % (name, key, x))
elif name in boolean_dicts:
if not isinstance(value, dict):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/orientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def _strong_orientations_of_a_mixed_graph(Dg, V, E):
while i < length:
u, v = E[i]
Dg.delete_edge(u, v)
if not (v in Dg.depth_first_search(u)):
if v not in Dg.depth_first_search(u):
# del E[i] in constant time
E[i] = E[-1]
E.pop()
Expand All @@ -490,7 +490,7 @@ def _strong_orientations_of_a_mixed_graph(Dg, V, E):
else:
Dg.add_edge(u, v)
Dg.delete_edge(v, u)
if not (u in Dg.depth_first_search(v)):
if u not in Dg.depth_first_search(v):
# del E[i] in constant time
E[i] = E[-1]
E.pop()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/interfaces/maxima_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ def sr_to_max(expr):
return EclObject(special_sage_to_max[op](*[sr_to_max(o) for o in expr.operands()]))
elif op == tuple:
return EclObject(([mlist], list(sr_to_max(op) for op in expr.operands())))
elif not (op in sage_op_dict):
elif op not in sage_op_dict:
# Maxima does some simplifications automatically by default
# so calling maxima(expr) can change the structure of expr
# op_max=caar(maxima(expr).ecl())
Expand Down
4 changes: 2 additions & 2 deletions src/sage/knots/knotinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2658,7 +2658,7 @@ def __getitem__(self, item):
[<KnotInfo.K6_1: '6_1'>, <KnotInfo.K6_2: '6_2'>, <KnotInfo.K6_3: '6_3'>]
"""
from sage.rings.integer import Integer
if not type(item) in (int, Integer):
if type(item) not in (int, Integer):
raise ValueError('item must be an integer')
l = self.list()
max_item = len(l)
Expand Down Expand Up @@ -2701,7 +2701,7 @@ def __call__(self, item):
return self[item]

from sage.rings.integer import Integer
if not type(item) in (int, Integer):
if type(item) not in (int, Integer):
raise ValueError('item must be an integer')
l = self.list()
max_item = len(l) + 1
Expand Down
4 changes: 2 additions & 2 deletions src/sage/knots/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ def _khovanov_homology_cached(self, height, ring=ZZ):
else:
m = matrix(ring, len(bases[(i,j)]), 0)
complexes[i] = m.transpose()
if not (i-1, j) in bases:
if (i-1, j) not in bases:
complexes[i-1] = matrix(ring, len(bases[(i,j)]), 0)
homologies = ChainComplex(complexes).homology()
return tuple(sorted(homologies.items()))
Expand Down Expand Up @@ -2313,7 +2313,7 @@ def seifert_circles(self):
while a not in par:
par.append(a)
posnext = C[(C.index(a) - 1) % 4]
if tails[posnext] == C and not [posnext] in result:
if tails[posnext] == C and [posnext] not in result:
a = posnext
else:
a = C[(C.index(a) + 1) % 4]
Expand Down
2 changes: 1 addition & 1 deletion src/sage/manifolds/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def __eq__(self, other):
diff = xs - xo
period = periods[ind]
if period is not None:
if not (diff/period in ZZ):
if diff/period not in ZZ:
return False
else:
if isinstance(diff, Expression) and not diff.is_trivial_zero():
Expand Down
9 changes: 5 additions & 4 deletions src/sage/quadratic_forms/genera/genus.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,12 @@ def is_2_adic_genus(genus_symbol_quintuple_list) -> bool:
return False
if s[1] == 2 and s[3] == 1:
if s[2] % 8 in (1, 7):
if not s[4] in (0, 2, 6):
if s[4] not in (0, 2, 6):
return False
if s[2] % 8 in (3, 5):
if not s[4] in (2, 4, 6):
if s[4] not in (2, 4, 6):
return False
if (s[1] - s[4]) % 2 == 1:
if (s[1] - s[4]) % 2:
return False
if s[3] == 0 and s[4] != 0:
return False
Expand Down Expand Up @@ -2802,7 +2802,8 @@ def direct_sum(self, other):
signature_pair = (p1 + p2, n1 + n2)

primes = [s.prime() for s in self.local_symbols()]
primes += [s.prime() for s in other.local_symbols() if not s.prime() in primes]
primes.extend(s.prime() for s in other.local_symbols()
if s.prime() not in primes)
primes.sort()
local_symbols = []
for p in primes:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/repl/rich_output/display_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,10 @@ def _rich_output_formatter(self, obj, rich_repr_kwds):
rich_output = self._promote_output(rich_output)
# check that the output container types are valid for the backend
supported = self._backend.supported_output()
if not (type(plain_text) in supported):
if type(plain_text) not in supported:
raise OutputTypeException(
'text output container not supported: {0}'.format(type(plain_text)))
if not (type(rich_output) in supported):
if type(rich_output) not in supported:
raise OutputTypeException(
'output container not supported: {0}'.format(type(rich_output)))
return plain_text, rich_output
Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/function_field/order_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(self, basis, check=True):
if check:
if self._module.rank() != field.degree():
raise ValueError("basis {} is not linearly independent".format(basis))
if not to_V(field(1)) in self._module:
if to_V(field(1)) not in self._module:
raise ValueError("the identity element must be in the module spanned by basis {}".format(basis))
if not all(to_V(a*b) in self._module for a in basis for b in basis):
raise ValueError("the module generated by basis {} must be closed under multiplication".format(basis))
Expand Down Expand Up @@ -399,7 +399,7 @@ def __init__(self, basis, check=True):
if check:
if self._module.rank() != field.degree():
raise ValueError("basis {} is not linearly independent".format(basis))
if not W.coordinate_vector(to(field(1))) in self._module:
if W.coordinate_vector(to(field(1))) not in self._module:
raise ValueError("the identity element must be in the module spanned by basis {}".format(basis))
if not all(W.coordinate_vector(to(a*b)) in self._module for a in basis for b in basis):
raise ValueError("the module generated by basis {} must be closed under multiplication".format(basis))
Expand Down Expand Up @@ -431,7 +431,7 @@ def _element_constructor_(self, f):

V, fr_V, to_V = F.vector_space()
W = self._ambient_space
if not W.coordinate_vector(to_V(f)) in self._module:
if W.coordinate_vector(to_V(f)) not in self._module:
raise TypeError("{} is not an element of {}".format(f, self))

return f
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/function_field/order_polymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ def ideal(self, *gens):
"""
if len(gens) == 1:
gens = gens[0]
if not type(gens) in (list,tuple):
if type(gens) not in (list,tuple):
gens = (gens,)
mgens = [g * b for g in gens for b in self._basis]
return self.ideal_with_gens_over_base(mgens)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/function_field/order_rational.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _element_constructor_(self, f):
except TypeError:
raise TypeError("unable to convert to an element of {}".format(F))

if not f.denominator() in self.function_field().constant_base_field():
if f.denominator() not in self.function_field().constant_base_field():
raise TypeError("%r is not an element of %r" % (f,self))

return f
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/number_field/number_field_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ def reduce(self, f):

R = self.number_field().maximal_order()

if not (f in R):
if f not in R:
raise TypeError("reduce only defined for integral elements")

Rbasis = R.basis()
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/number_field/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ def ring_generators(self):
gens.append(g)
n.append(g.absolute_minpoly().degree())
W = A.span([to_V(x) for x in monomials(gens, n)])
remaining = [x for x in remaining if not to_V(x) in W]
remaining = [x for x in remaining if to_V(x) not in W]
return Sequence(gens, immutable=True)

@cached_method
Expand Down Expand Up @@ -1590,7 +1590,7 @@ def _element_constructor_(self, x):
if not isinstance(x, Element) or x.parent() is not self._K:
x = self._K(x)
V, _, embedding = self._K.vector_space()
if not embedding(x) in self._module_rep:
if embedding(x) not in self._module_rep:
raise TypeError("Not an element of the order.")
return self._element_type(self, x)

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/pari_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __pow__(self, other):
sage: a^2
9
"""
if not (other in PariRing()):
if other not in PariRing():
other = Pari(other)
return self.__class__(self.__x ** other.__x, parent=_inst)

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/pbori/ll.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def eliminate(polys, on_the_fly=False, prot=False, reduction_function=None,
lm = p.lex_lead()
if lm.deg() == 1:

if not (lm in linear_leading_monomials):
if lm not in linear_leading_monomials:
linear_leading_monomials.add(lm)
linear_leads.append(p)
else:
Expand Down
Loading

0 comments on commit 4dcda50

Please sign in to comment.