Skip to content

Commit

Permalink
gh-38921: fixing ruff E714
Browse files Browse the repository at this point in the history
    
about using "not in"

### 📝 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: #38921
Reported by: Frédéric Chapoton
Reviewer(s): Martin Rubey
  • Loading branch information
Release Manager committed Nov 14, 2024
2 parents d7c66fa + 980078e commit 4314f17
Show file tree
Hide file tree
Showing 19 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/sage/algebras/shuffle_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def _element_constructor_(self, x):
if isinstance(P, ShuffleAlgebra):
if P is self:
return x
if not (P is self.base_ring()):
if P is not self.base_ring():
return self.element_class(self, x.monomial_coefficients())
if isinstance(P, DualPBWBasis):
return self(P.expansion(x))
Expand Down
4 changes: 2 additions & 2 deletions src/sage/crypto/block_cipher/miniaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ def GF_to_binary(self, G):
return B(S)
# G is a matrix over GF(16)
elif isinstance(G, Matrix_dense):
if not (G.base_ring() is K):
if G.base_ring() is not K:
raise TypeError("input G must be an element of GF(16), a list of elements of GF(16), or a matrix over GF(16)")
S = "".join(str(self._GF_to_bin[G[i][j]])
for i in range(G.nrows()) for j in range(G.ncols()))
Expand Down Expand Up @@ -1772,7 +1772,7 @@ def GF_to_integer(self, G):
return [self._GF_to_int[g] for g in G]
# G is a matrix over GF(16)
elif isinstance(G, Matrix_dense):
if not (G.base_ring() is K):
if G.base_ring() is not K:
raise TypeError("input G must be an element of GF(16), a list of elements of GF(16), or a matrix over GF(16)")
return [self._GF_to_int[G[i][j]] for i in range(G.nrows()) for j in range(G.ncols())]
# the type of G doesn't match the supported types
Expand Down
2 changes: 1 addition & 1 deletion src/sage/dynamics/arithmetic_dynamics/berkovich_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def conjugate(self, M, adjugate=False, new_ideal=None):
new_system = self._system.conjugate(M, adjugate=adjugate)
system_domain = new_system.domain()
if new_ideal is None:
if not system_domain.base_ring() is QQ:
if system_domain.base_ring() is not QQ:
new_ideal = system_domain.base_ring().prime_above(self.domain().ideal())
else:
new_ideal = self.domain().ideal()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,7 @@ def is_perfect(self, certificate=False):
return True if not certificate else None

answer = self.is_odd_hole_free(certificate=certificate)
if not (answer is True):
if answer is not True:
return answer

return self_complement.is_odd_hole_free(certificate=certificate)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/groups/abelian_gps/abelian_aut.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def is_subgroup_of(self, G):
"""
if not isinstance(G, AbelianGroupAutomorphismGroup_gap):
raise ValueError("input must be an instance of AbelianGroup_gap")
if not self.ambient() is G.ambient():
if self.ambient() is not G.ambient():
return False
return G.gap().IsSubsemigroup(self).sage()

Expand Down
2 changes: 1 addition & 1 deletion src/sage/groups/abelian_gps/abelian_group_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def is_subgroup_of(self, G):
"""
if not isinstance(G, AbelianGroup_gap):
raise ValueError("input must be an instance of AbelianGroup_gap")
if not self.ambient() is G.ambient():
if self.ambient() is not G.ambient():
return False
return G.gap().IsSubsemigroup(self).sage()

Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/affine_gps/group_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def __init__(self, parent, A, b=0, convert=True, check=True):
# Note: the coercion framework expects that we raise TypeError for invalid input
if not isinstance(A, Matrix):
raise TypeError('A must be a matrix')
if not (A.parent() is parent.matrix_space()):
if A.parent() is not parent.matrix_space():
raise TypeError('A must be an element of ' + str(parent.matrix_space()))
if not (b.parent() is parent.vector_space()):
if b.parent() is not parent.vector_space():
raise TypeError('b must be an element of ' + str(parent.vector_space()))
parent._element_constructor_check(A, b)
super().__init__(parent)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/interfaces/psage.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __del__(self):
except OSError:
pass

if not (self._expect is None):
if self._expect is not None:
cmd = 'kill -9 %s' % self._expect.pid
os.system(cmd)

Expand Down
2 changes: 1 addition & 1 deletion src/sage/logic/boolformula.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ def convert_opt(self, tree):
:func:`~sage.logic.logicparser.apply_func()` in
:mod:`~sage.logic.logicparser`.
"""
if not isinstance(tree[1], tuple) and not (tree[1] is None):
if not isinstance(tree[1], tuple) and tree[1] is not None:
lval = ('prop', tree[1])
else:
lval = tree[1]
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/rest_index_of_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def local_filter(f, name):
else:
return not any(hasattr(s, name) for s in superclasses)
else:
return inspect.isclass(root) or not (f is gen_rest_table_index)
return inspect.isclass(root) or f is not gen_rest_table_index

def can_import(f):
# poke it to provoke a lazy import to resolve
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/fp_graded/morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def lift(self, f, verbose=False):
M = f.domain()

# It is an error to call this function with incompatible arguments.
if not f.codomain() is N:
if f.codomain() is not N:
raise ValueError('the codomains of this homomorphism and the homomorphism '
'we are lifting over are different')

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/finite_rings/galois_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _element_constructor_(self, x, check=True):
else:
raise RuntimeError("Automorphism was not a power of Frobenius")
elif isinstance(x, FrobeniusEndomorphism_finite_field):
if check and not x.domain() is k:
if check and x.domain() is not k:
raise ValueError("Not an automorphism of the correct finite field")
n = x.power()
elif isinstance(x, list) and len(x) == 1 and x[0] in ZZ:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/invariants/invariant_theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def diff(j):
dg = g.form().derivative(x,h-j).derivative(y,j)
return (-1)**j * binomial(h,j) * df * dg
tv = scalar * sum([diff(j) for j in range(h+1)])
if not tv.parent() is R:
if tv.parent() is not R:
S = tv.parent()
x = S(x)
y = S(y)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@ def __init__(self, base_ring, extra_units, names=None, normalize=True, category=
sage: L = R.localization(x**2 + 1) # needs sage.libs.pari
sage: TestSuite(L).run()
"""
if type(extra_units) is tuple:
if isinstance(extra_units, tuple):
extra_units = list(extra_units)
if not type(extra_units) is list:
elif not isinstance(extra_units, list):
extra_units = [extra_units]

from sage.rings.polynomial.laurent_polynomial_ring_base import LaurentPolynomialRing_generic
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -10415,7 +10415,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True):
from sage.groups.additive_abelian.additive_abelian_group import AdditiveAbelianGroup

# input checks
if not type(S) is list:
if not isinstance(S, list):
raise TypeError("first argument must be a list")
if b not in self:
raise TypeError("second argument must be an element of this field")
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/multi_polynomial_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def degree(self, x=None, std_grading=False):
return Integer(self.element().degree(None))
return self.weighted_degree(self.parent().term_order().weights())
if isinstance(x, MPolynomial):
if not x.parent() is self.parent():
if x.parent() is not self.parent():
try:
x = self.parent().coerce(x)
except TypeError:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/multi_polynomial_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def _singular_(self, singular=None):
try:
self.ring()._singular_(singular).set_ring()
I = self.__singular
if not (I.parent() is singular):
if I.parent() is not singular:
raise ValueError
I._check_valid()
return I
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/polynomial_quotient_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def create_key(self, ring, polynomial, names=None):
raise TypeError("ring must be a polynomial ring")
if not isinstance(polynomial, polynomial_element.Polynomial):
raise TypeError("must be a polynomial")
if not polynomial.parent() is ring:
if polynomial.parent() is not ring:
raise TypeError("polynomial must be in ring")

c = polynomial.leading_coefficient()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/valuation/gauss_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def create_key(self, domain, v=None):
if v is None:
v = domain.base_ring().valuation()

if not v.domain() is domain.base_ring():
if v.domain() is not domain.base_ring():
raise ValueError("the domain of v must be the base ring of domain but %r is not defined over %r but over %r" % (v, domain.base_ring(), v.domain()))
if not v.is_discrete_valuation():
raise ValueError("v must be a discrete valuation but %r is not" % (v,))
Expand Down

0 comments on commit 4314f17

Please sign in to comment.