Skip to content

Commit 0d8231f

Browse files
author
Release Manager
committed
gh-35892: fixing some pep8 warnings in schemes/toric <!-- 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 fixes some pycodestyle warning in `schemes/toric` <!-- 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: #35892 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 519e2ce + 1f4f8ca commit 0d8231f

File tree

6 files changed

+95
-91
lines changed

6 files changed

+95
-91
lines changed

src/sage/schemes/toric/fano_variety.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@
107107
# The first example of the tutorial is taken from
108108
# CPRFanoToricVariety_field.anticanonical_hypersurface
109109

110-
111-
#*****************************************************************************
110+
# ****************************************************************************
112111
# Copyright (C) 2010 Andrey Novoseltsev <[email protected]>
113112
# Copyright (C) 2010 William Stein <[email protected]>
114113
#
115114
# Distributed under the terms of the GNU General Public License (GPL)
116115
#
117-
# http://www.gnu.org/licenses/
118-
#*****************************************************************************
116+
# https://www.gnu.org/licenses/
117+
# ****************************************************************************
119118

120119
import re
121120

@@ -527,7 +526,7 @@ def CPRFanoToricVariety(Delta=None,
527526
raise ValueError("the origin (point #%d) cannot be used for a "
528527
"coordinate!\nGot: %s"
529528
% (Delta_polar.origin(), coordinate_points))
530-
point_to_ray = dict()
529+
point_to_ray = {}
531530
for n, point in enumerate(coordinate_points):
532531
point_to_ray[point] = n
533532
# This can be simplified if LatticePolytopeClass is adjusted.
@@ -568,7 +567,7 @@ def CPRFanoToricVariety(Delta=None,
568567
make_simplicial=make_simplicial)
569568
# Now create yet another fan making sure that the order of the rays is
570569
# the same as requested (it is a bit difficult to get it from the start)
571-
trans = dict()
570+
trans = {}
572571
for n, ray in enumerate(fan.rays()):
573572
trans[n] = rays.index(ray)
574573
cones = tuple(tuple(sorted(trans[r] for r in cone.ambient_ray_indices()))
@@ -1147,7 +1146,7 @@ def cartesian_product(self, other,
11471146
Delta_polar = LatticePolytope(fan.rays())
11481147

11491148
points = Delta_polar.points()
1150-
point_to_ray = dict()
1149+
point_to_ray = {}
11511150
coordinate_points = []
11521151
for ray_index, ray in enumerate(fan.rays()):
11531152
point = points.index(ray)
@@ -1230,7 +1229,7 @@ def resolve(self, **kwds):
12301229
"subdivision!" % Delta_polar.origin())
12311230
if new_points:
12321231
coordinate_points = coordinate_points + new_points
1233-
point_to_ray = dict()
1232+
point_to_ray = {}
12341233
for n, point in enumerate(coordinate_points):
12351234
point_to_ray[point] = n
12361235
else:

src/sage/schemes/toric/ideal.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,17 @@ def __init__(self, A,
227227
"""
228228
self._A = matrix(ZZ, A)
229229
if polynomial_ring:
230-
if (names!='z') or (base_ring is not QQ):
230+
if names != 'z' or base_ring is not QQ:
231231
raise ValueError('you must not specify both variable names and a polynomial ring')
232-
self._names = [str(_) for _ in polynomial_ring.gens()]
232+
self._names = [str(g) for g in polynomial_ring.gens()]
233233
self._base_ring = polynomial_ring.base_ring()
234234
ring = polynomial_ring
235235
else:
236236
self._names = names
237237
self._base_ring = base_ring
238238
ring = self._init_ring('degrevlex')
239239

240-
if algorithm=='HostenSturmfels':
240+
if algorithm == 'HostenSturmfels':
241241
ideal = self._ideal_HostenSturmfels()
242242
else:
243243
raise ValueError(f'algorithm = {algorithm} is not known')
@@ -396,9 +396,9 @@ def _ideal_quotient_by_variable(self, ring, ideal, n):
396396
"""
397397
N = self.nvariables()
398398
y = list(ring.gens())
399-
x = [ y[i-n] for i in range(N) ]
400-
y_to_x = dict(zip(x,y))
401-
x_to_y = dict(zip(y,x))
399+
x = [y[i - n] for i in range(N)]
400+
y_to_x = dict(zip(x, y))
401+
x_to_y = dict(zip(y, x))
402402
# swap variables such that the n-th variable becomes the last one
403403
J = ideal.subs(y_to_x)
404404

@@ -410,7 +410,7 @@ def _ideal_quotient_by_variable(self, ring, ideal, n):
410410
# x_n = y[0] # the cheapest variable in the revlex order
411411
def subtract(e, power):
412412
l = list(e)
413-
return tuple([l[0]-power] + l[1:])
413+
return tuple([l[0] - power] + l[1:])
414414

415415
def divide_by_x_n(p):
416416
d_old = p.dict()

src/sage/schemes/toric/library.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
Multivariate Polynomial Ring in x, y, z over Rational Field
2828
"""
2929

30-
#*****************************************************************************
30+
# ****************************************************************************
3131
# Copyright (C) 2010 Volker Braun <[email protected]>
3232
# Copyright (C) 2010 Andrey Novoseltsev <[email protected]>
3333
#
3434
# This program is free software: you can redistribute it and/or modify
3535
# it under the terms of the GNU General Public License as published by
3636
# the Free Software Foundation, either version 2 of the License, or
3737
# (at your option) any later version.
38-
# http://www.gnu.org/licenses/
39-
#*****************************************************************************
38+
# https://www.gnu.org/licenses/
39+
# ****************************************************************************
4040

4141
from sage.structure.sage_object import SageObject
4242

@@ -121,30 +121,30 @@
121121
(-1, -1, -1), (-1, 1, -1), (1, -1, -1), (1, 1, -1)],
122122
[[0,1,2,3],[4,5,6,7],[0,1,7,6],[4,5,3,2],[0,2,5,7],[4,6,1,3]] ],
123123
'BCdlOG':[
124-
[(-1, 0, 0, 2, 3), # 0
125-
( 0,-1, 0, 2, 3), # 1
126-
( 0, 0,-1, 2, 3), # 2
127-
( 0, 0,-1, 1, 2), # 3
128-
( 0, 0, 0,-1, 0), # 4
129-
( 0, 0, 0, 0,-1), # 5
130-
( 0, 0, 0, 2, 3), # 6
131-
( 0, 0, 1, 2, 3), # 7
132-
( 0, 0, 2, 2, 3), # 8
133-
( 0, 0, 1, 1, 1), # 9
124+
[(-1, 0, 0, 2, 3), # 0
125+
( 0,-1, 0, 2, 3), # 1
126+
( 0, 0,-1, 2, 3), # 2
127+
( 0, 0,-1, 1, 2), # 3
128+
( 0, 0, 0,-1, 0), # 4
129+
( 0, 0, 0, 0,-1), # 5
130+
( 0, 0, 0, 2, 3), # 6
131+
( 0, 0, 1, 2, 3), # 7
132+
( 0, 0, 2, 2, 3), # 8
133+
( 0, 0, 1, 1, 1), # 9
134134
( 0, 1, 2, 2, 3), # 10
135135
( 0, 1, 3, 2, 3), # 11
136-
( 1, 0, 4, 2, 3)], # 12
137-
[ [0,6,7,1,4], [0,6,10,2,4], [0,6,1,2,4], [0,9,7,1,5], [0,6,7,1,5],
138-
[0,6,10,2,5], [0,6,1,2,5], [0,9,1,4,5], [0,6,10,4,11],[0,6,7,4,11],
139-
[0,6,10,5,11], [0,9,7,5,11], [0,6,7,5,11], [0,9,4,5,11], [0,10,4,5,11],
140-
[0,9,7,1,8], [0,9,1,4,8], [0,7,1,4,8], [0,9,7,11,8], [0,9,4,11,8],
141-
[0,7,4,11,8], [0,10,2,4,3], [0,1,2,4,3], [0,10,2,5,3], [0,1,2,5,3],
142-
[0,10,4,5,3], [0,1,4,5,3], [12,6,7,1,4], [12,6,10,2,4],[12,6,1,2,4],
143-
[12,9,7,1,5], [12,6,7,1,5], [12,6,10,2,5], [12,6,1,2,5], [12,9,1,4,5],
136+
( 1, 0, 4, 2, 3)], # 12
137+
[ [0,6,7,1,4], [0,6,10,2,4], [0,6,1,2,4], [0,9,7,1,5], [0,6,7,1,5],
138+
[0,6,10,2,5], [0,6,1,2,5], [0,9,1,4,5], [0,6,10,4,11],[0,6,7,4,11],
139+
[0,6,10,5,11], [0,9,7,5,11], [0,6,7,5,11], [0,9,4,5,11], [0,10,4,5,11],
140+
[0,9,7,1,8], [0,9,1,4,8], [0,7,1,4,8], [0,9,7,11,8], [0,9,4,11,8],
141+
[0,7,4,11,8], [0,10,2,4,3], [0,1,2,4,3], [0,10,2,5,3], [0,1,2,5,3],
142+
[0,10,4,5,3], [0,1,4,5,3], [12,6,7,1,4], [12,6,10,2,4],[12,6,1,2,4],
143+
[12,9,7,1,5], [12,6,7,1,5], [12,6,10,2,5], [12,6,1,2,5], [12,9,1,4,5],
144144
[12,6,10,4,11],[12,6,7,4,11], [12,6,10,5,11],[12,9,7,5,11],[12,6,7,5,11],
145-
[12,9,4,5,11], [12,10,4,5,11],[12,9,7,1,8], [12,9,1,4,8], [12,7,1,4,8],
145+
[12,9,4,5,11], [12,10,4,5,11],[12,9,7,1,8], [12,9,1,4,8], [12,7,1,4,8],
146146
[12,9,7,11,8], [12,9,4,11,8], [12,7,4,11,8], [12,10,2,4,3],[12,1,2,4,3],
147-
[12,10,2,5,3], [12,1,2,5,3], [12,10,4,5,3], [12,1,4,5,3] ] ],
147+
[12,10,2,5,3], [12,1,2,5,3], [12,10,4,5,3], [12,1,4,5,3] ] ],
148148
'BCdlOG_base':[
149149
[(-1, 0, 0),
150150
( 0,-1, 0),
@@ -535,7 +535,7 @@ def P(self, n, names='z+', base_ring=QQ):
535535
if n <= 0:
536536
raise ValueError("only projective spaces of positive dimension "
537537
"can be constructed!\nGot: %s" % n)
538-
m = identity_matrix(n).augment(matrix(n, 1, [-1]*n))
538+
m = identity_matrix(n).augment(matrix(n, 1, [-1] * n))
539539
charts = [list(range(i)) + list(range(i + 1, n + 1))
540540
for i in range(n + 1)]
541541
return CPRFanoToricVariety(
@@ -935,9 +935,15 @@ def Cube_deformation(self,k, names=None, base_ring=QQ):
935935
if k < 0:
936936
raise ValueError("cube deformations X_k are defined only for "
937937
"non-negative k!\nGot: %s" % k)
938-
rays = lambda kappa: matrix([[ 1, 1, 2*kappa+1],[ 1,-1, 1],[-1, 1, 1],[-1,-1, 1],
939-
[-1,-1,-1],[-1, 1,-1],[ 1,-1,-1],[ 1, 1,-1]])
940-
cones = [[0,1,2,3],[4,5,6,7],[0,1,7,6],[4,5,3,2],[0,2,5,7],[4,6,1,3]]
938+
939+
def rays(kappa):
940+
return matrix([[1, 1, 2 * kappa + 1], [1, -1, 1],
941+
[-1, 1, 1], [-1, -1, 1],
942+
[-1, -1, -1], [-1, 1, -1],
943+
[1, -1, -1], [1, 1, -1]])
944+
945+
cones = [[0, 1, 2, 3], [4, 5, 6, 7], [0, 1, 7, 6],
946+
[4, 5, 3, 2], [0, 2, 5, 7], [4, 6, 1, 3]]
941947
fan = Fan(cones, rays(k))
942948
return ToricVariety(fan, coordinate_names=names)
943949

@@ -1277,7 +1283,7 @@ def WP(self, *q, **kw):
12771283

12781284
L = ToricLattice(m)
12791285
L_sub = L.submodule([L(q)])
1280-
Q = L/L_sub
1286+
Q = L / L_sub
12811287
rays = []
12821288
cones = []
12831289
w = list(range(m))
@@ -1286,7 +1292,7 @@ def WP(self, *q, **kw):
12861292
b = L_basis[i]
12871293
v = Q.coordinate_vector(Q(b))
12881294
rays = rays + [v]
1289-
w_c = w[:i] + w[i+1:]
1295+
w_c = w[:i] + w[i + 1:]
12901296
cones = cones + [tuple(w_c)]
12911297
fan = Fan(cones,rays)
12921298
return ToricVariety(fan, coordinate_names=names, base_ring=base_ring)

src/sage/schemes/toric/morphism.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344
1 connected components over (1, 2), each with 2 irreducible components.
345345
"""
346346

347-
#*****************************************************************************
347+
# ****************************************************************************
348348
# Copyright (C) 2011 Volker Braun <[email protected]>
349349
# Copyright (C) 2010 Andrey Novoseltsev <[email protected]>
350350
# Copyright (C) 2006 William Stein <[email protected]>
@@ -353,8 +353,8 @@
353353
# it under the terms of the GNU General Public License as published by
354354
# the Free Software Foundation, either version 2 of the License, or
355355
# (at your option) any later version.
356-
# http://www.gnu.org/licenses/
357-
#*****************************************************************************
356+
# https://www.gnu.org/licenses/
357+
# ****************************************************************************
358358

359359
# For now, the scheme morphism base class cannot derive from Morphism
360360
# since this would clash with elliptic curves. So we derive only on
@@ -640,7 +640,7 @@ def _reverse_ray_map(self):
640640
"""
641641
orbit = self.parent().domain()
642642
codomain_fan = self.parent().codomain().fan()
643-
reverse_ray_dict = dict()
643+
reverse_ray_dict = {}
644644
for n1, n2 in self._ray_map.items():
645645
ray_index = codomain_fan.rays().index(n1)
646646
if n2.is_zero():
@@ -760,7 +760,7 @@ def pullback_divisor(self, divisor):
760760
codomain_rays = self.codomain().fan().rays()
761761
for ray in self.domain().fan().rays():
762762
ray = codomain_rays[self._reverse_ray_map()[ray]]
763-
value = divisor.function_value(ray) - m*ray
763+
value = divisor.function_value(ray) - m * ray
764764
values.append(value)
765765
return self.domain().divisor(values)
766766

@@ -855,9 +855,9 @@ def __init__(self, parent, fan_morphism, check=True):
855855
to Rational polyhedral fan in 1-d lattice N.
856856
"""
857857
SchemeMorphism.__init__(self, parent)
858-
if check and self.domain().fan()!=fan_morphism.domain_fan():
858+
if check and self.domain().fan() != fan_morphism.domain_fan():
859859
raise ValueError('the fan morphism domain must be the fan of the domain')
860-
if check and self.codomain().fan()!=fan_morphism.codomain_fan():
860+
if check and self.codomain().fan() != fan_morphism.codomain_fan():
861861
raise ValueError('the fan morphism codomain must be the fan of the codomain')
862862
self._fan_morphism = fan_morphism
863863

@@ -1816,7 +1816,7 @@ def _make_fiber_component(self):
18161816
ker = fm.kernel().basis()
18171817
m = fm.matrix() * base_cone.lattice().basis_matrix()
18181818
base_cone_preimg = [m.solve_left(r) for r in base_cone.rays()]
1819-
L = fm.domain_fan().lattice().span(ker+base_cone_preimg).saturation()
1819+
L = fm.domain_fan().lattice().span(ker + base_cone_preimg).saturation()
18201820

18211821
cone_L = Cone([L.coordinates(r) for r in defining_cone.rays()])
18221822
L_quotient = cone_L.sublattice_quotient()
@@ -1833,7 +1833,7 @@ def projection(ray):
18331833
cones.append(Cone(projected_rays))
18341834
fiber_fan = Fan(cones)
18351835

1836-
ray_index_map = dict()
1836+
ray_index_map = {}
18371837
for ray in star_rays:
18381838
ray_index = fm.domain_fan().rays().index(ray)
18391839
projected_ray = fiber_fan.lattice()(projection(ray))
@@ -1939,7 +1939,7 @@ def _image_ray_multiplicity(self, fiber_ray):
19391939
d = gcd(ray)
19401940
if d * fiber_ray != ray:
19411941
continue
1942-
if multiplicity is not None and d>multiplicity:
1942+
if multiplicity is not None and d > multiplicity:
19431943
continue
19441944
multiplicity = d
19451945
image_ray_index = index
@@ -1984,7 +1984,7 @@ def pullback_divisor(self, divisor):
19841984
for ray in self.domain().fan().rays():
19851985
image_ray_index, multiplicity = self._image_ray_multiplicity(ray)
19861986
image_ray = codomain_rays[image_ray_index]
1987-
value = divisor.function_value(image_ray) - m*image_ray
1987+
value = divisor.function_value(image_ray) - m * image_ray
19881988
value /= multiplicity
19891989
values.append(value)
19901990
return self.domain().divisor(values)

0 commit comments

Comments
 (0)