Skip to content

Commit 41fa630

Browse files
author
Release Manager
committed
gh-35916: some pep8 cleanup in schemes/affine and schemes/curves <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description This is fixing many pycodestyle warnings in the `schemes` folder, mostly in `affine` and `curves` subfolders <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [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 accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35916 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe, Travis Scrimshaw
2 parents 174c410 + fdae513 commit 41fa630

14 files changed

+287
-269
lines changed

src/sage/schemes/affine/affine_homset.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
4646
from sage.schemes.generic.homset import SchemeHomset_points, SchemeHomset_generic
4747

48+
4849
# *******************************************************************
4950
# Affine varieties
5051
# *******************************************************************
@@ -274,63 +275,63 @@ def points(self, **kwds):
274275
numerical = False
275276
# Then X must be a subscheme
276277
dim_ideal = X.defining_ideal().dimension()
277-
if dim_ideal < 0: # no points
278+
if dim_ideal < 0: # no points
278279
return []
279-
if dim_ideal == 0: # if X zero-dimensional
280+
if dim_ideal == 0: # if X zero-dimensional
280281
rat_points = []
281282
AS = X.ambient_space()
282283
N = AS.dimension_relative()
283284
BR = X.base_ring()
284-
#need a lexicographic ordering for elimination
285+
# need a lexicographic ordering for elimination
285286
R = PolynomialRing(BR, N, AS.gens(), order='lex')
286287
I = R.ideal(X.defining_polynomials())
287288
I0 = R.ideal(0)
288-
#Determine the points through elimination
289-
#This is much faster than using the I.variety() function on each affine chart.
289+
# Determine the points through elimination
290+
# This is much faster than using the I.variety() function on each affine chart.
290291
G = I.groebner_basis()
291292
if G != [1]:
292293
P = {}
293294
points = [P]
294-
#work backwards from solving each equation for the possible
295-
#values of the next coordinate
295+
# work backwards from solving each equation for the possible
296+
# values of the next coordinate
296297
for i in range(len(G) - 1, -1, -1):
297298
new_points = []
298299
good = 0
299300
for P in points:
300-
#substitute in our dictionary entry that has the values
301-
#of coordinates known so far. This results in a single
302-
#variable polynomial (by elimination)
301+
# substitute in our dictionary entry that has the values
302+
# of coordinates known so far. This results in a single
303+
# variable polynomial (by elimination)
303304
L = G[i].substitute(P)
304305
if R(L).degree() > 0:
305306
if numerical:
306307
for pol in L.univariate_polynomial().roots(multiplicities=False):
307308
r = L.variables()[0]
308309
varindex = R.gens().index(r)
309-
P.update({R.gen(varindex):pol})
310+
P.update({R.gen(varindex): pol})
310311
new_points.append(copy(P))
311312
good = 1
312313
else:
313314
L = L.factor()
314-
#the linear factors give the possible rational values of
315-
#this coordinate
315+
# the linear factors give the possible rational values of
316+
# this coordinate
316317
for pol, pow in L:
317318
if pol.degree() == 1 and len(pol.variables()) == 1:
318319
good = 1
319320
r = pol.variables()[0]
320321
varindex = R.gens().index(r)
321-
#add this coordinates information to
322-
#each dictionary entry
323-
P.update({R.gen(varindex):-pol.constant_coefficient() /
324-
pol.monomial_coefficient(r)})
322+
# add this coordinates information to
323+
# each dictionary entry
324+
P.update({R.gen(varindex):
325+
-pol.constant_coefficient() / pol.monomial_coefficient(r)})
325326
new_points.append(copy(P))
326327
else:
327328
new_points.append(P)
328329
good = 1
329330
if good:
330331
points = new_points
331-
#the dictionary entries now have values for all coordinates
332-
#they are the rational solutions to the equations
333-
#make them into affine points
332+
# the dictionary entries now have values for all coordinates
333+
# they are the rational solutions to the equations
334+
# make them into affine points
334335
for i in range(len(points)):
335336
if numerical:
336337
if len(points[i]) == N:
@@ -350,19 +351,19 @@ def points(self, **kwds):
350351
prec = kwds.pop('precision', 53)
351352
if is_RationalField(R) or R == ZZ:
352353
if not B > 0:
353-
raise TypeError("a positive bound B (= %s) must be specified"%B)
354+
raise TypeError("a positive bound B (= %s) must be specified" % B)
354355
from sage.schemes.affine.affine_rational_point import enum_affine_rational_field
355-
return enum_affine_rational_field(self,B)
356+
return enum_affine_rational_field(self, B)
356357
if R in NumberFields():
357358
if not B > 0:
358-
raise TypeError("a positive bound B (= %s) must be specified"%B)
359+
raise TypeError("a positive bound B (= %s) must be specified" % B)
359360
from sage.schemes.affine.affine_rational_point import enum_affine_number_field
360361
return enum_affine_number_field(self, bound=B, tolerance=tol, precision=prec)
361362
elif isinstance(R, FiniteField):
362363
from sage.schemes.affine.affine_rational_point import enum_affine_finite_field
363364
return enum_affine_finite_field(self)
364365
else:
365-
raise TypeError("unable to enumerate points over %s"%R)
366+
raise TypeError("unable to enumerate points over %s" % R)
366367

367368
def numerical_points(self, F=None, **kwds):
368369
"""
@@ -447,7 +448,7 @@ def numerical_points(self, F=None, **kwds):
447448
if not is_AffineSpace(X) and X.base_ring() in Fields():
448449
# Then X must be a subscheme
449450
dim_ideal = X.defining_ideal().dimension()
450-
if dim_ideal != 0: # no points
451+
if dim_ideal != 0: # no points
451452
return []
452453
else:
453454
return []

src/sage/schemes/affine/affine_morphism.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ def __init__(self, parent, polys, check=True):
194194
"""
195195
if check:
196196
if not isinstance(polys, (list, tuple)):
197-
raise TypeError("polys (=%s) must be a list or tuple"%polys)
197+
raise TypeError("polys (=%s) must be a list or tuple" % polys)
198198
source_ring = parent.domain().ambient_space().coordinate_ring()
199199
target = parent.codomain().ambient_space()
200200
if len(polys) != target.ngens():
201-
raise ValueError("there must be %s polynomials"%target.ngens())
201+
raise ValueError("there must be %s polynomials" % target.ngens())
202202
try:
203203
polys = [source_ring(poly) for poly in polys]
204204
except TypeError: # maybe given quotient ring elements
@@ -207,14 +207,15 @@ def __init__(self, parent, polys, check=True):
207207
except (TypeError, AttributeError):
208208
# must be a rational function since we cannot have
209209
# rational functions for quotient rings
210+
source_field = source_ring.base_ring().fraction_field()
210211
try:
211-
if not all(p.base_ring().fraction_field()==source_ring.base_ring().fraction_field() for p in polys):
212-
raise TypeError("polys (=%s) must be rational functions in %s"%(polys, source_ring))
212+
if not all(p.base_ring().fraction_field() == source_field for p in polys):
213+
raise TypeError("polys (=%s) must be rational functions in %s" % (polys, source_ring))
213214
K = FractionField(source_ring)
214215
polys = [K(p) for p in polys]
215216
# polys = [source_ring(poly.numerator())/source_ring(poly.denominator()) for poly in polys]
216-
except TypeError: # can't seem to coerce
217-
raise TypeError("polys (=%s) must be rational functions in %s"%(polys, source_ring))
217+
except TypeError: # can't seem to coerce
218+
raise TypeError("polys (=%s) must be rational functions in %s" % (polys, source_ring))
218219
check = False
219220

220221
SchemeMorphism_polynomial.__init__(self, parent, polys, check)
@@ -263,7 +264,7 @@ def __call__(self, x, check=True):
263264
try:
264265
x = self.domain()(x)
265266
except (TypeError, NotImplementedError):
266-
raise TypeError("%s fails to convert into the map's domain %s, but a `pushforward` method is not properly implemented"%(x, self.domain()))
267+
raise TypeError("%s fails to convert into the map's domain %s, but a `pushforward` method is not properly implemented" % (x, self.domain()))
267268

268269
R = x.domain().coordinate_ring()
269270
if R is self.base_ring():
@@ -307,7 +308,7 @@ def __eq__(self, right):
307308
return False
308309
if self.parent() != right.parent():
309310
return False
310-
return all(val == right._polys[i] for i,val in enumerate(self._polys))
311+
return all(val == right._polys[i] for i, val in enumerate(self._polys))
311312

312313
def __ne__(self, right):
313314
"""
@@ -336,7 +337,7 @@ def __ne__(self, right):
336337
return True
337338
if self.parent() != right.parent():
338339
return True
339-
return any(val != right._polys[i] for i,val in enumerate(self._polys))
340+
return any(val != right._polys[i] for i, val in enumerate(self._polys))
340341

341342
@lazy_attribute
342343
def _fastpolys(self):
@@ -422,11 +423,11 @@ def _fast_eval(self, x):
422423
P = []
423424
for i in range(len(self._fastpolys[0])):
424425
# Check if denominator is the identity;
425-
#if not, then must append the fraction evaluated at the point
426+
# if not, then must append the fraction evaluated at the point
426427
if self._fastpolys[1][i] is R.one():
427428
P.append(self._fastpolys[0][i](*x))
428429
else:
429-
P.append(self._fastpolys[0][i](*x)/self._fastpolys[1][i](*x))
430+
P.append(self._fastpolys[0][i](*x) / self._fastpolys[1][i](*x))
430431
return P
431432

432433
def homogenize(self, n):
@@ -597,32 +598,32 @@ def homogenize(self, n):
597598
# create dictionary for mapping of coordinate rings
598599
R = self.domain().ambient_space().coordinate_ring()
599600
S = A.ambient_space().coordinate_ring()
600-
D = dict(zip(R.gens(), [S.gen(i) for i in range(N+1) if i != ind[0]]))
601+
D = dict(zip(R.gens(), [S.gen(i) for i in range(N + 1) if i != ind[0]]))
601602

602603
if self.codomain().is_projective():
603-
L = [self[i].denominator() for i in range(M+1)]
604-
l = [prod(L[:j] + L[j+1:M+1]) for j in range(M+1)]
605-
F = [S(R(self[i].numerator()*l[i]).subs(D)) for i in range(M+1)]
604+
L = [self[i].denominator() for i in range(M + 1)]
605+
l = [prod(L[:j] + L[j + 1:M + 1]) for j in range(M + 1)]
606+
F = [S(R(self[i].numerator() * l[i]).subs(D)) for i in range(M + 1)]
606607
else:
607608
# clear the denominators if a rational function
608609
L = [self[i].denominator() for i in range(M)]
609-
l = [prod(L[:j] + L[j+1:M]) for j in range(M)]
610-
F = [S(R(self[i].numerator()*l[i]).subs(D)) for i in range(M)]
610+
l = [prod(L[:j] + L[j + 1:M]) for j in range(M)]
611+
F = [S(R(self[i].numerator() * l[i]).subs(D)) for i in range(M)]
611612
F.insert(ind[1], S(R(prod(L)).subs(D))) # coerce in case l is a constant
612613

613614
try:
614615
# remove possible gcd of the polynomials
615616
g = gcd(F)
616-
F = [S(f/g) for f in F]
617+
F = [S(f / g) for f in F]
617618
# remove possible gcd of coefficients
618619
gc = gcd([f.content() for f in F])
619-
F = [S(f/gc) for f in F]
620-
except (AttributeError, ValueError, NotImplementedError, TypeError, ArithmeticError): # no gcd
620+
F = [S(f / gc) for f in F]
621+
except (AttributeError, ValueError, NotImplementedError, TypeError, ArithmeticError): # no gcd
621622
pass
622623

623624
# homogenize
624-
d = max([F[i].degree() for i in range(M+1)])
625-
F = [F[i].homogenize(str(newvar))*newvar**(d-F[i].degree()) for i in range(M+1)]
625+
d = max([F[i].degree() for i in range(M + 1)])
626+
F = [F[i].homogenize(str(newvar)) * newvar**(d - F[i].degree()) for i in range(M + 1)]
626627

627628
return H(F)
628629

@@ -678,7 +679,7 @@ def as_dynamical_system(self):
678679
if R not in _Fields:
679680
return DynamicalSystem_affine(list(self), self.domain())
680681
if isinstance(R, FiniteField):
681-
return DynamicalSystem_affine_finite_field(list(self), self.domain())
682+
return DynamicalSystem_affine_finite_field(list(self), self.domain())
682683
return DynamicalSystem_affine_field(list(self), self.domain())
683684

684685
def global_height(self, prec=None):
@@ -885,7 +886,7 @@ def jacobian(self):
885886
return self.__jacobian
886887
except AttributeError:
887888
pass
888-
self.__jacobian = jacobian(list(self),self.domain().ambient_space().gens())
889+
self.__jacobian = jacobian(list(self), self.domain().ambient_space().gens())
889890
return self.__jacobian
890891

891892
def _matrix_times_polymap_(self, mat, h):
@@ -1025,6 +1026,7 @@ def degree(self):
10251026
max_degree = poly.degree()
10261027
return max_degree
10271028

1029+
10281030
class SchemeMorphism_polynomial_affine_space_field(SchemeMorphism_polynomial_affine_space):
10291031

10301032
@cached_method
@@ -1210,7 +1212,7 @@ def reduce_base_field(self):
12101212
R = new_domain.coordinate_ring()
12111213
H = Hom(new_domain, new_codomain)
12121214
if isinstance(g[0], FractionFieldElement):
1213-
return H([R(G.numerator())/R(G.denominator()) for G in g])
1215+
return H([R(G.numerator()) / R(G.denominator()) for G in g])
12141216
return H([R(G) for G in g])
12151217

12161218
def indeterminacy_locus(self):
@@ -1241,7 +1243,7 @@ def indeterminacy_locus(self):
12411243
"""
12421244
A = self.domain()
12431245
X = A.subscheme(0) # affine space as a subscheme
1244-
return (self*X.hom(A.gens(), A)).indeterminacy_locus()
1246+
return (self * X.hom(A.gens(), A)).indeterminacy_locus()
12451247

12461248
def indeterminacy_points(self, F=None):
12471249
r"""
@@ -1316,7 +1318,7 @@ def image(self):
13161318
"""
13171319
X = self.domain().subscheme(0)
13181320
e = X.embedding_morphism()
1319-
return (self*e).image()
1321+
return (self * e).image()
13201322

13211323

13221324
class SchemeMorphism_polynomial_affine_space_finite_field(SchemeMorphism_polynomial_affine_space_field):
@@ -1342,7 +1344,7 @@ def _fast_eval(self, x):
13421344
[1, 1, 2]
13431345
"""
13441346
R = self.domain().ambient_space().coordinate_ring()
1345-
P=[]
1347+
P = []
13461348
for i in range(len(self._fastpolys[0])):
13471349
r = self._fastpolys[0][i](*x)
13481350
if self._fastpolys[1][i] is R.one():
@@ -1356,7 +1358,7 @@ def _fast_eval(self, x):
13561358
p = self.base_ring().characteristic()
13571359
r = Integer(r) % p
13581360
s = Integer(s) % p
1359-
P.append(r/s)
1361+
P.append(r / s)
13601362
return P
13611363

13621364

@@ -1441,7 +1443,7 @@ def representatives(self):
14411443
reprs = []
14421444
for r in h.representatives():
14431445
i = X.projective_embedding(0, h.domain().ambient_space())
1444-
reprs.append(r*i)
1446+
reprs.append(r * i)
14451447
else:
14461448
reprs = []
14471449
for r in h.representatives():
@@ -1563,5 +1565,5 @@ def image(self):
15631565
return self.homogenize(0).image()
15641566

15651567
e = Y.projective_embedding(0)
1566-
h = (e*self).homogenize(0)
1568+
h = (e * self).homogenize(0)
15671569
return h.image().affine_patch(0, Y.ambient_space())

0 commit comments

Comments
 (0)