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

Commit

Permalink
Trac #32758: fix E713 and E714 in schemes
Browse files Browse the repository at this point in the history
about negative comparison using "is not"

URL: https://trac.sagemath.org/32758
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Jonathan Kliem
  • Loading branch information
Release Manager committed Oct 28, 2021
2 parents 50776da + c8499d1 commit c5a8783
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 59 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=8761bf411523c8980d9e404ae9c2f5dec8b6d733
md5=57bc67c3d99d2fffa8688745cc101990
cksum=472330691
sha1=b789b0cad7547f9b699a305d5cfe6a4b67d353df
md5=ad65b7da919dcff932eb34a98793504b
cksum=2565222951
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
50c7af6955632686157cd8dac2d8d764f6d41fb3
dc6e96cb4344704cb6779ff68e024d06063d50ee
2 changes: 1 addition & 1 deletion src/sage/schemes/affine/affine_homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def numerical_points(self, F=None, **kwds):
from sage.schemes.affine.affine_space import is_AffineSpace
if F is None:
F = CC
if not F in Fields() or not hasattr(F, 'precision'):
if F not in Fields() or not hasattr(F, 'precision'):
raise TypeError('F must be a numerical field')
X = self.codomain()
if X.base_ring() not in NumberFields():
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/affine/affine_subscheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def is_smooth(self, point=None):
False
"""
R = self.ambient_space().coordinate_ring()
if not point is None:
if point is not None:
self._check_satisfies_equations(point)
point_subs = dict(zip(R.gens(), point))
Jac = self.Jacobian().subs(point_subs)
Expand Down
8 changes: 4 additions & 4 deletions src/sage/schemes/curves/affine_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def tangents(self, P, factor=True):
# divide T by that power of vars[1]
T = self.ambient_space().coordinate_ring()(dict([((v[0],v[1] - t), h) for (v,h) in T.dict().items()]))
# T is homogeneous in var[0], var[1] if nonconstant, so dehomogenize
if not T in self.base_ring():
if T not in self.base_ring():
if T.degree(vars[0]) > 0:
T = T(vars[0], 1)
roots = T.univariate_polynomial().roots()
Expand Down Expand Up @@ -982,7 +982,7 @@ def projection(self, indices, AS=None):
raise ValueError("(=%s) must be a list or tuple of length between 2 and (=%s), inclusive" % (indices, n - 1))
if len(set(indices)) < len(indices):
raise ValueError("(=%s) must be a list or tuple of distinct indices or variables" % indices)
if not AS is None:
if AS is not None:
if not is_AffineSpace(AS):
raise TypeError("(=%s) must be an affine space" % AS)
if AS.dimension_relative() != len(indices):
Expand Down Expand Up @@ -2145,11 +2145,11 @@ def _nonsingular_model(self):
basis = list(gbasis)
syzygy = {}
for i in range(n):
S = k[R._first_ngens(i+1)]
S = k[R._first_ngens(i + 1)]
while basis:
f = basis.pop()
if f in S:
if not i in syzygy and f:
if i not in syzygy and f:
syzygy[i] = f
else:
basis.append(f)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/curves/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ def singular_points(self, F=None):
if not self.base_ring() in Fields():
raise TypeError("curve must be defined over a field")
F = self.base_ring()
elif not F in Fields():
raise TypeError("(=%s) must be a field"%F)
elif F not in Fields():
raise TypeError("(=%s) must be a field" % F)
X = self.singular_subscheme()
return [self.point(p, check=False) for p in X.rational_points(F=F)]

Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/curves/projective_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def projection(self, P=None, PS=None):
raise TypeError("this curve is already a plane curve")
if self.base_ring() not in Fields():
raise TypeError("this curve must be defined over a field")
if not PS is None:
if PS is not None:
if not is_ProjectiveSpace(PS):
raise TypeError("(=%s) must be a projective space" % PS)
if PS.dimension_relative() != n - 1:
Expand Down Expand Up @@ -455,7 +455,7 @@ def projection(self, P=None, PS=None):
Q = self(P)
except TypeError:
pass
if not Q is None:
if Q is not None:
raise TypeError("(=%s) must be a point not on this curve" % P)
try:
Q = self.ambient_space()(P)
Expand Down
3 changes: 1 addition & 2 deletions src/sage/schemes/elliptic_curves/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,8 @@ def is_cm_j_invariant(j, method='new'):
True
"""
# First we check that j is an algebraic number:

from sage.rings.all import NumberFieldElement, NumberField
if not isinstance(j, NumberFieldElement) and not j in QQ:
if not isinstance(j, NumberFieldElement) and j not in QQ:
raise NotImplementedError("is_cm_j_invariant() is only implemented for number field elements")

# for j in ZZ we have a lookup-table:
Expand Down
6 changes: 3 additions & 3 deletions src/sage/schemes/elliptic_curves/ell_egros.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ def egros_get_j(S=[], proof=None, verbose=False):
P = urst(P)
x = P[0]
y = P[1]
j = x**3 /w
assert j-1728 == y**2 /w
j = x**3 / w
assert j - 1728 == y**2 / w
if is_possible_j(j, S):
if not j in jlist:
if j not in jlist:
if verbose:
print("Adding possible j = ", j)
sys.stdout.flush()
Expand Down
10 changes: 5 additions & 5 deletions src/sage/schemes/elliptic_curves/ell_modular_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def modular_symbol_space(E, sign, base_ring, bound=None):
Modular Symbols space of dimension 1 for Gamma_0(11) of weight 2 with sign -1 over Finite Field of size 37
"""
if not sign in [-1,0,1]:
if sign not in [-1, 0, 1]:
raise TypeError('sign must -1, 0 or 1')
N = E.conductor()
M = ModularSymbols(N, sign=sign, base_ring=base_ring)
Expand Down Expand Up @@ -323,12 +323,12 @@ def __init__(self, E, sign, nap=1000):
"""
from sage.libs.eclib.newforms import ECModularSymbol

if not sign in [-1,1]:
if sign not in [-1, 1]:
raise TypeError('sign must -1 or 1')
self._sign = ZZ(sign)
self._E = E
self._scaling = 1 if E.discriminant()>0 else ZZ(1)/2
self._implementation="eclib"
self._implementation = "eclib"
self._base_ring = QQ
# The ECModularSymbol class must be initialized with sign=0 to compute minus symbols
self._modsym = ECModularSymbol(E, int(sign==1), nap)
Expand Down Expand Up @@ -436,11 +436,11 @@ def __init__(self, E, sign, normalize="L_ratio"):
[1, 1, 1, 1, 1, 1, 1, 1]
"""
if not sign in [-1,1]:
if sign not in [-1, 1]:
raise TypeError('sign must -1 or 1')
self._sign = ZZ(sign)
self._E = E
self._implementation="sage"
self._implementation = "sage"
self._normalize = normalize
self._modsym = E.modular_symbol_space(sign=self._sign)
self._base_ring = self._modsym.base_ring()
Expand Down
11 changes: 6 additions & 5 deletions src/sage/schemes/elliptic_curves/ell_rational_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2376,12 +2376,12 @@ def _compute_gens(self, proof,
# progress (see trac #1949).
X = self.mwrank('-p 100 -S '+str(sat_bound))
verbose_verbose("Calling mwrank shell.")
if not 'The rank and full Mordell-Weil basis have been determined unconditionally' in X:
if 'The rank and full Mordell-Weil basis have been determined unconditionally' not in X:
msg = 'Generators not provably computed.'
if proof:
raise RuntimeError('%s\n%s'%(X,msg))
raise RuntimeError('%s\n%s' % (X, msg))
else:
verbose_verbose("Warning -- %s"%msg, level=1)
verbose_verbose("Warning -- %s" % msg, level=1)
proved = False
else:
proved = True
Expand Down Expand Up @@ -4714,8 +4714,9 @@ def isogenies_prime_degree(self, l=None):
if isinstance(l, list):
isogs = []
i = 0
while i<len(l):
isogenies = [f for f in self.isogenies_prime_degree(l[i]) if not f in isogs]
while i < len(l):
isogenies = [f for f in self.isogenies_prime_degree(l[i])
if f not in isogs]
isogs.extend(isogenies)
i += 1
return isogs
Expand Down
9 changes: 5 additions & 4 deletions src/sage/schemes/elliptic_curves/isogeny_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ def _compute(self, verbose=False):

def add_tup(t):
for T in [t, [t[1], t[0], t[2], 0]]:
if not T in tuples:
if T not in tuples:
tuples.append(T)
if verbose:
sys.stdout.write(" -added tuple %s..." % T[:3])
Expand All @@ -818,7 +818,7 @@ def add_tup(t):
sys.stdout.flush()
add_tup([0,ncurves,d,phi])
ncurves += 1
if not d in degs:
if d not in degs:
degs.append(d)
if verbose:
sys.stdout.write("... relevant degrees: %s..." % degs)
Expand Down Expand Up @@ -909,8 +909,9 @@ def add_tup(t):
allQs = {} # keys: discriminants d
# values: lists of equivalence classes of
# primitive forms of discriminant d
def find_quadratic_form(d,n):
if not d in allQs:

def find_quadratic_form(d, n):
if d not in allQs:
from sage.quadratic_forms.binary_qf import BinaryQF_reduced_representatives

allQs[d] = BinaryQF_reduced_representatives(d, primitive_only=True)
Expand Down
16 changes: 8 additions & 8 deletions src/sage/schemes/elliptic_curves/isogeny_small_degree.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def Psi(l, use_stored=True):
sage: assert Psi(7, use_stored=True) == Psi(7, use_stored=False)
sage: assert Psi(13, use_stored=True) == Psi(13, use_stored=False) # not tested (very long time)
"""
if not l in [2, 3, 5, 7, 13]:
if l not in [2, 3, 5, 7, 13]:
raise ValueError("Genus zero primes are 2, 3, 5, 7 or 13.")

R = PolynomialRing(ZZ, 2, 'Xt')
Expand Down Expand Up @@ -276,7 +276,7 @@ def isogenies_prime_degree_genus_0(E, l=None, minimal_models=True):
Isogeny of degree 5 from Elliptic Curve defined by y^2 + x*y + y = x^3 - x - 2 over Rational Field to Elliptic Curve defined by y^2 + x*y + y = x^3 - 76*x + 298 over Rational Field]
"""
if not l in [2, 3, 5, 7, 13, None]:
if l not in [2, 3, 5, 7, 13, None]:
raise ValueError("%s is not a genus 0 prime."%l)
F = E.base_ring()
j = E.j_invariant()
Expand Down Expand Up @@ -1423,7 +1423,7 @@ def _hyperelliptic_isogeny_data(l):
ValueError: 37 must be one of [11, 17, 19, 23, 29, 31, 41, 47, 59, 71].
"""
if not l in hyperelliptic_primes:
if l not in hyperelliptic_primes:
raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes))
data = {}
Zu = PolynomialRing(ZZ,'u')
Expand Down Expand Up @@ -1692,7 +1692,7 @@ def isogenies_prime_degree_genus_plus_0(E, l=None, minimal_models=True):
return sum([isogenies_prime_degree_genus_plus_0(E, ell, minimal_models=minimal_models)
for ell in hyperelliptic_primes],[])

if not l in hyperelliptic_primes:
if l not in hyperelliptic_primes:
raise ValueError("%s must be one of %s." % (l, hyperelliptic_primes))

F = E.base_ring()
Expand Down Expand Up @@ -1782,7 +1782,7 @@ def isogenies_prime_degree_genus_plus_0_j0(E, l, minimal_models=True):
sage: isogenies_prime_degree_genus_plus_0_j0(E,17)
[Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6]
"""
if not l in hyperelliptic_primes:
if l not in hyperelliptic_primes:
raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes))
F = E.base_field()
if E.j_invariant() != 0:
Expand Down Expand Up @@ -1873,7 +1873,7 @@ def isogenies_prime_degree_genus_plus_0_j1728(E, l, minimal_models=True):
sage: [(p,len(isogenies_prime_degree_genus_plus_0_j1728(Emin,p))) for p in [17, 29, 41]]
[(17, 2), (29, 2), (41, 2)]
"""
if not l in hyperelliptic_primes:
if l not in hyperelliptic_primes:
raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes))
F = E.base_ring()
if E.j_invariant() != 1728:
Expand Down Expand Up @@ -2352,10 +2352,10 @@ def isogenies_prime_degree(E, l, minimal_models=True):
if l==p:
return isogenies_prime_degree_general(E,l, minimal_models=minimal_models)

if l in [5,7,13] and not p in [2,3]:
if l in [5,7,13] and p not in [2,3]:
return isogenies_prime_degree_genus_0(E,l, minimal_models=minimal_models)

if l in hyperelliptic_primes and not p in [2,3]:
if l in hyperelliptic_primes and p not in [2,3]:
return isogenies_prime_degree_genus_plus_0(E,l, minimal_models=minimal_models)

j = E.j_invariant()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/kraus.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def check_Kraus_global(c4, c6, assume_nonsingular=False, debug=False):
a1list = [d[1] for d in dat]
a1 = K.solve_CRT(a1list,P2list, check=True)
# See comment below: this is needed for when we combine with the primes above 3.
if not a1 in three: # three.divides(a1) causes a segfault
if a1 not in three: # three.divides(a1) causes a segfault
a1 = 3*a1

# Using this a1, recompute the local a3's:
Expand Down
6 changes: 3 additions & 3 deletions src/sage/schemes/generic/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,11 @@ def __init__(self, R, S=None, category=None):
<class 'sage.schemes.generic.scheme.AffineScheme_with_category'>
"""
from sage.categories.commutative_rings import CommutativeRings
if not R in CommutativeRings():
if R not in CommutativeRings():
raise TypeError("R (={}) must be a commutative ring".format(R))
self.__R = R
if not S is None:
if not S in CommutativeRings():
if S is not None:
if S not in CommutativeRings():
raise TypeError("S (={}) must be a commutative ring".format(S))
if not R.has_coerce_map_from(S):
raise ValueError("There must be a natural map S --> R, but S = {} and R = {}".format(S, R))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/plane_conics/con_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ def parametrization(self, point=None, morphism=True):
...
ValueError: The conic self (=Projective Conic Curve over Rational Field defined by x^2 + y^2) is not smooth, hence does not have a parametrization.
"""
if (not self._parametrization is None) and not point:
if (self._parametrization is not None) and not point:
par = self._parametrization
else:
if not self.is_smooth():
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/plane_quartics/quartic_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def QuarticCurve(F, PP=None, check=False):
if not(F.is_homogeneous() and F.degree()==4):
raise ValueError("Argument F (=%s) must be a homogeneous polynomial of degree 4"%F)

if not PP is None:
if PP is not None:
if not is_ProjectiveSpace(PP) and PP.dimension == 2:
raise ValueError("Argument PP (=%s) must be a projective plane"%PP)
raise ValueError(f"Argument PP (={PP}) must be a projective plane")
else:
PP = ProjectiveSpace(P)

Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/projective/projective_homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def numerical_points(self, F=None, **kwds):
from sage.schemes.projective.projective_space import is_ProjectiveSpace
if F is None:
F = CC
if not F in Fields() or not hasattr(F, 'precision'):
if F not in Fields() or not hasattr(F, 'precision'):
raise TypeError('F must be a numerical field')
X = self.codomain()
if X.base_ring() not in NumberFields():
Expand Down
10 changes: 6 additions & 4 deletions src/sage/schemes/projective/projective_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,18 +1594,20 @@ def rational_preimages(self, Q, k=1):
k = ZZ(k)
if k <= 0:
raise ValueError("k (=%s) must be a positive integer" % k)
#first check if subscheme
# first check if subscheme
from sage.schemes.projective.projective_subscheme import AlgebraicScheme_subscheme_projective
if isinstance(Q, AlgebraicScheme_subscheme_projective):
return Q.preimage(self, k)

#else assume a point
# else assume a point
BR = self.base_ring()
if k > 1 and not self.is_endomorphism():
raise TypeError("must be an endomorphism of projective space")
if not Q in self.codomain():
if Q not in self.codomain():
raise TypeError("point must be in codomain of self")
if isinstance(BR.base_ring(),(ComplexField_class, RealField_class,RealIntervalField_class, ComplexIntervalField_class)):
if isinstance(BR.base_ring(), (ComplexField_class, RealField_class,
RealIntervalField_class,
ComplexIntervalField_class)):
raise NotImplementedError("not implemented over precision fields")
PS = self.domain().ambient_space()
N = PS.dimension_relative()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/projective/projective_subscheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def is_smooth(self, point=None):
sage: H.is_smooth() # one of the few cases where the cone over the subvariety is smooth
True
"""
if not point is None:
if point is not None:
self._check_satisfies_equations(point)
R = self.ambient_space().coordinate_ring()
point_subs = dict(zip(R.gens(), point))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/toric/homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def _finite_field_enumerator(self, finite_field=None):
variety = self.codomain()
if finite_field is None:
finite_field = variety.base_ring()
if not finite_field in FiniteFields():
if finite_field not in FiniteFields():
raise ValueError('not a finite field')
return FiniteFieldPointEnumerator(variety.fan(), finite_field)

Expand Down
Loading

0 comments on commit c5a8783

Please sign in to comment.