Skip to content

Commit b84e184

Browse files
author
Release Manager
committed
gh-35909: some pep8 fixes in topology/ <!-- 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 fixes many small pycodestyle warnings in the `topology` folder, except mainly E226 <!-- 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: #35909 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Matthias Köppe
2 parents 4d198fd + d60d328 commit b84e184

12 files changed

+290
-255
lines changed

src/sage/topology/cell_complex.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class :class:`~sage.homology.delta_complex.DeltaComplex`
7979
sage: from sage.topology.cell_complex import GenericCellComplex
8080
sage: A = GenericCellComplex()
8181
"""
82-
def __eq__(self,right):
82+
def __eq__(self, right):
8383
"""
8484
Comparisons of cell complexes are not implemented.
8585
@@ -94,7 +94,7 @@ def __eq__(self,right):
9494
"""
9595
raise NotImplementedError
9696

97-
def __ne__(self,right):
97+
def __ne__(self, right):
9898
"""
9999
Comparisons of cell complexes are not implemented.
100100
@@ -254,7 +254,7 @@ def f_vector(self):
254254
sage: cubical_complexes.KleinBottle().f_vector()
255255
[1, 42, 84, 42]
256256
"""
257-
return [self._f_dict()[n] for n in range(-1, self.dimension()+1)]
257+
return [self._f_dict()[n] for n in range(-1, self.dimension() + 1)]
258258

259259
def _f_dict(self):
260260
"""
@@ -290,7 +290,7 @@ def euler_characteristic(self):
290290
sage: cubical_complexes.KleinBottle().euler_characteristic()
291291
0
292292
"""
293-
return sum([(-1)**n * self.f_vector()[n+1] for n in range(self.dimension() + 1)])
293+
return sum((-1)**n * self.f_vector()[n + 1] for n in range(self.dimension() + 1))
294294

295295
############################################################
296296
# end of methods using self.cells()
@@ -543,9 +543,6 @@ def homology(self, dim=None, base_ring=ZZ, subcomplex=None,
543543
sage: S.homology(generators=True) # optional - sage.modules
544544
{0: [], 1: 0, 2: [(Z, sigma_2)]}
545545
"""
546-
from sage.topology.cubical_complex import CubicalComplex
547-
from sage.topology.simplicial_complex import SimplicialComplex
548-
from sage.modules.free_module import VectorSpace
549546
from sage.homology.homology_group import HomologyGroup
550547

551548
if dim is not None:
@@ -599,8 +596,8 @@ def homology(self, dim=None, base_ring=ZZ, subcomplex=None,
599596
return answer.get(dim, zero)
600597

601598
def cohomology(self, dim=None, base_ring=ZZ, subcomplex=None,
602-
generators=False, algorithm='pari',
603-
verbose=False, reduced=True):
599+
generators=False, algorithm='pari',
600+
verbose=False, reduced=True):
604601
r"""
605602
The reduced cohomology of this cell complex.
606603

src/sage/topology/cubical_complex.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _translate(self, vec):
226226
"""
227227
t = self.__tuple
228228
embed = max(len(t), len(vec))
229-
t = t + ((0,0),) * (embed-len(t))
229+
t = t + ((0, 0),) * (embed-len(t))
230230
vec = tuple(vec) + (0,) * (embed-len(vec))
231231
new = []
232232
for (a, b) in zip(t, vec):
@@ -367,7 +367,7 @@ def face(self, n, upper=True):
367367
new = t[idx][1]
368368
else:
369369
new = t[idx][0]
370-
return Cube(t[0:idx] + ((new,new),) + t[idx+1:])
370+
return Cube(t[0:idx] + ((new, new),) + t[idx+1:])
371371

372372
def faces(self):
373373
"""
@@ -380,8 +380,8 @@ def faces(self):
380380
sage: C.faces()
381381
[[2,2] x [3,4], [1,2] x [4,4], [1,1] x [3,4], [1,2] x [3,3]]
382382
"""
383-
upper = [self.face(i,True) for i in range(self.dimension())]
384-
lower = [self.face(i,False) for i in range(self.dimension())]
383+
upper = [self.face(i, True) for i in range(self.dimension())]
384+
lower = [self.face(i, False) for i in range(self.dimension())]
385385
return upper + lower
386386

387387
def faces_as_pairs(self):
@@ -464,7 +464,7 @@ def _compare_for_gluing(self, other):
464464
self_tuple = self.tuple()
465465
other_tuple = other.tuple()
466466
nondegen = (list(zip(self.nondegenerate_intervals(),
467-
other.nondegenerate_intervals()))
467+
other.nondegenerate_intervals()))
468468
+ [(len(self_tuple), len(other_tuple))])
469469
old = (-1, -1)
470470
self_added = 0
@@ -540,10 +540,10 @@ def _triangulation_(self):
540540
6
541541
"""
542542
from .simplicial_complex import Simplex
543-
if self.dimension() < 0: # the empty cube
544-
return [Simplex(())] # the empty simplex
543+
if self.dimension() < 0: # the empty cube
544+
return [Simplex(())] # the empty simplex
545545
v = tuple([max(j) for j in self.tuple()])
546-
if self.dimension() == 0: # just v
546+
if self.dimension() == 0: # just v
547547
return [Simplex((v,))]
548548
simplices = []
549549
for i in range(self.dimension()):
@@ -594,7 +594,7 @@ def alexander_whitney(self, dim):
594594
nu = 0
595595
for i in J:
596596
for j in Jprime:
597-
if j<i:
597+
if j < i:
598598
nu += 1
599599
t = self.tuple()
600600
left = []
@@ -717,7 +717,7 @@ def _repr_(self):
717717
sage: C1._repr_()
718718
'[1,1] x [2,3] x [4,5]'
719719
"""
720-
s = ["[%s,%s]"%(str(x), str(y)) for (x,y) in self.__tuple]
720+
s = ("[%s,%s]" % (str(x), str(y)) for x, y in self.__tuple)
721721
return " x ".join(s)
722722

723723
def _latex_(self):
@@ -1074,7 +1074,7 @@ def cells(self, subcomplex=None):
10741074
sub_facets = {}
10751075
dimension = max([cube.dimension() for cube in self._facets])
10761076
# initialize the lists: add each maximal cube to Cells and sub_facets
1077-
for i in range(-1,dimension+1):
1077+
for i in range(-1, dimension+1):
10781078
Cells[i] = set([])
10791079
sub_facets[i] = set([])
10801080
for f in self._facets:
@@ -1214,7 +1214,7 @@ def chain_complex(self, subcomplex=None, augmented=False,
12141214
differentials[0] = mat
12151215
current = vertices
12161216
# now loop from 1 to dimension of the complex
1217-
for dim in range(1,self.dimension()+1):
1217+
for dim in range(1, self.dimension()+1):
12181218
if verbose:
12191219
print(" starting dimension %s" % dim)
12201220
if (dim, subcomplex) in self._complex:
@@ -1488,9 +1488,9 @@ def disjoint_union(self, other):
14881488
zero = [0] * max(embedded_left, embedded_right)
14891489
facets = []
14901490
for f in self.maximal_cells():
1491-
facets.append(Cube([[0,0]]).product(f._translate(zero)))
1491+
facets.append(Cube([[0, 0]]).product(f._translate(zero)))
14921492
for f in other.maximal_cells():
1493-
facets.append(Cube([[1,1]]).product(f._translate(zero)))
1493+
facets.append(Cube([[1, 1]]).product(f._translate(zero)))
14941494
return CubicalComplex(facets)
14951495

14961496
def wedge(self, other):
@@ -1522,7 +1522,7 @@ def wedge(self, other):
15221522
embedded_right = len(tuple(other.maximal_cells()[0]))
15231523
translate_left = [-a[0] for a in self.maximal_cells()[0]] + [0] * embedded_right
15241524
translate_right = [-a[0] for a in other.maximal_cells()[0]]
1525-
point_right = Cube([[0,0]] * embedded_left)
1525+
point_right = Cube([[0, 0]] * embedded_left)
15261526

15271527
facets = []
15281528
for f in self.maximal_cells():
@@ -1584,7 +1584,7 @@ def connected_sum(self, other):
15841584
# start assembling the facets in the connected sum: first, the
15851585
# cylinder on the removed face.
15861586
new_facets = []
1587-
cylinder = removed.product(Cube([[0,1]]))
1587+
cylinder = removed.product(Cube([[0, 1]]))
15881588
# don't want to include the ends of the cylinder, so don't
15891589
# include the last pair of faces. therefore, choose faces up
15901590
# to removed.dimension(), not cylinder.dimension().
@@ -1596,13 +1596,13 @@ def connected_sum(self, other):
15961596
CL = list(cube.tuple())
15971597
for (idx, L) in insert_self:
15981598
CL[idx:idx] = L
1599-
CL.append((0,0))
1599+
CL.append((0, 0))
16001600
new_facets.append(Cube(CL))
16011601
for cube in other_facets:
16021602
CL = list(cube.tuple())
16031603
for (idx, L) in insert_other:
16041604
CL[idx:idx] = L
1605-
CL.append((1,1))
1605+
CL.append((1, 1))
16061606
new_facets.append(Cube(CL)._translate(translate))
16071607
return CubicalComplex(new_facets)
16081608

@@ -1813,7 +1813,7 @@ class CubicalComplexExamples():
18131813
Cubical complex with 256 vertices and 6560 cubes
18141814
"""
18151815

1816-
def Sphere(self,n):
1816+
def Sphere(self, n):
18171817
r"""
18181818
A cubical complex representation of the `n`-dimensional sphere,
18191819
formed by taking the boundary of an `(n+1)`-dimensional cube.
@@ -1826,7 +1826,7 @@ def Sphere(self,n):
18261826
sage: cubical_complexes.Sphere(7)
18271827
Cubical complex with 256 vertices and 6560 cubes
18281828
"""
1829-
return CubicalComplex(Cube([[0,1]]*(n+1)).faces())
1829+
return CubicalComplex(Cube([[0, 1]]*(n+1)).faces())
18301830

18311831
def Torus(self):
18321832
r"""

src/sage/topology/delta_complex.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,14 @@ def chain_complex(self, subcomplex=None, augmented=False,
640640
empty_simplex = 0
641641
vertices = self.n_cells(0, subcomplex=subcomplex)
642642
old = vertices
643-
old_real = [x for x in old if x is not None] # get rid of faces not in subcomplex
643+
old_real = [x for x in old if x is not None] # remove faces not in subcomplex
644644
n = len(old_real)
645645
differentials[0] = matrix(base_ring, empty_simplex, n, n*empty_simplex*[1])
646646
# current is list of simplices in dimension dim
647647
# current_real is list of simplices in dimension dim, with None filtered out
648648
# old is list of simplices in dimension dim-1
649649
# old_real is list of simplices in dimension dim-1, with None filtered out
650-
for dim in range(1,self.dimension()+1):
650+
for dim in range(1, self.dimension()+1):
651651
current = list(self.n_cells(dim, subcomplex=subcomplex))
652652
current_real = [x for x in current if x is not None]
653653
i = 0
@@ -665,10 +665,10 @@ def chain_complex(self, subcomplex=None, augmented=False,
665665
for row in s:
666666
if old[row] is not None:
667667
actual_row = translate[row]
668-
if (actual_row,col) in mat_dict:
669-
mat_dict[(actual_row,col)] += sign
668+
if (actual_row, col) in mat_dict:
669+
mat_dict[(actual_row, col)] += sign
670670
else:
671-
mat_dict[(actual_row,col)] = sign
671+
mat_dict[(actual_row, col)] = sign
672672
sign *= -1
673673
col += 1
674674
differentials[dim] = matrix(base_ring, len(old_real), len(current_real), mat_dict)
@@ -827,17 +827,17 @@ def join(self, other):
827827
data.append(self.n_cells(0) + other.n_cells(0))
828828
bdries = {}
829829
for l_idx in range(len(self.n_cells(0))):
830-
bdries[(0,l_idx,-1,0)] = l_idx
830+
bdries[(0, l_idx, -1, 0)] = l_idx
831831
for r_idx in range(len(other.n_cells(0))):
832-
bdries[(-1,0,0,r_idx)] = len(self.n_cells(0)) + r_idx
832+
bdries[(-1, 0, 0, r_idx)] = len(self.n_cells(0)) + r_idx
833833
# dimension of the join:
834834
maxdim = self.dimension() + other.dimension() + 1
835835
# now for the d-cells, d>0:
836-
for d in range(1,maxdim+1):
836+
for d in range(1, maxdim+1):
837837
d_cells = []
838838
positions = {}
839839
new_idx = 0
840-
for k in range(-1,d+1):
840+
for k in range(-1, d+1):
841841
n = d-1-k
842842
# d=n+k. need a k-cell from self and an n-cell from other
843843
if k == -1:
@@ -919,11 +919,11 @@ def suspension(self, n=1):
919919
sage: S3.homology()
920920
{0: 0, 1: 0, 2: 0, 3: Z}
921921
"""
922-
if n<0:
922+
if n < 0:
923923
raise ValueError("n must be non-negative")
924-
if n==0:
924+
if n == 0:
925925
return self
926-
if n==1:
926+
if n == 1:
927927
return self.join(delta_complexes.Sphere(0))
928928
return self.suspension().suspension(int(n-1))
929929

@@ -975,8 +975,8 @@ def product(self, other):
975975
for w in other.n_cells(0):
976976
# one vertex for each pair (v,w)
977977
# store its indices in bdries; store its boundary in vertices
978-
bdries[(0,l_idx,0,r_idx, ((0,0),))] = len(vertices)
979-
vertices.append(()) # add new vertex (simplex with empty bdry)
978+
bdries[(0, l_idx, 0, r_idx, ((0, 0),))] = len(vertices)
979+
vertices.append(()) # add new vertex (simplex with empty bdry)
980980
r_idx += 1
981981
l_idx += 1
982982
data.append(tuple(vertices))
@@ -988,7 +988,7 @@ def product(self, other):
988988
new = {}
989989
for d in range(1, maxdim+1):
990990
for k in range(d+1):
991-
for n in range(d-k,d+1):
991+
for n in range(d-k, d+1):
992992
k_idx = 0
993993
for k_cell in self.n_cells(k):
994994
n_idx = 0
@@ -1011,8 +1011,8 @@ def product(self, other):
10111011
bdry_list = []
10121012
for i in range(d+1):
10131013
face_path = path[:i] + path[i+1:]
1014-
if ((i<d and path[i][0] == path[i+1][0]) or
1015-
(i>0 and path[i][0] == path[i-1][0])):
1014+
if ((i < d and path[i][0] == path[i+1][0]) or
1015+
(i > 0 and path[i][0] == path[i-1][0])):
10161016
# this k-simplex
10171017
k_face_idx = k_idx
10181018
k_face_dim = k
@@ -1021,12 +1021,12 @@ def product(self, other):
10211021
k_face_idx = k_cell[path[i][0]]
10221022
k_face_dim = k-1
10231023
tail = []
1024-
for j in range(i,d):
1024+
for j in range(i, d):
10251025
tail.append((face_path[j][0]-1,
1026-
face_path[j][1]))
1026+
face_path[j][1]))
10271027
face_path = face_path[:i] + tuple(tail)
1028-
if ((i<d and path[i][1] == path[i+1][1]) or
1029-
(i>0 and path[i][1] == path[i-1][1])):
1028+
if ((i < d and path[i][1] == path[i+1][1]) or
1029+
(i > 0 and path[i][1] == path[i-1][1])):
10301030
# this n-simplex
10311031
n_face_idx = n_idx
10321032
n_face_dim = n
@@ -1035,7 +1035,7 @@ def product(self, other):
10351035
n_face_idx = n_cell[path[i][1]]
10361036
n_face_dim = n-1
10371037
tail = []
1038-
for j in range(i,d):
1038+
for j in range(i, d):
10391039
tail.append((face_path[j][0],
10401040
face_path[j][1]-1))
10411041
face_path = face_path[:i] + tuple(tail)
@@ -1383,7 +1383,7 @@ def _epi_from_standard_simplex(self, idx=-1, dim=None):
13831383
faces_dict = {}
13841384
for cell in n_cells:
13851385
if n > 1:
1386-
faces = [tuple(simplex_cells[n-1][cell[j]]) for j in range(0,n+1)]
1386+
faces = [tuple(simplex_cells[n-1][cell[j]]) for j in range(n+1)]
13871387
one_cell = dict(zip(faces, self_cells[n][n_cells[cell]]))
13881388
else:
13891389
temp = dict(zip(cell, self_cells[n][n_cells[cell]]))
@@ -1638,7 +1638,7 @@ class DeltaComplexExamples():
16381638
False
16391639
"""
16401640

1641-
def Sphere(self,n):
1641+
def Sphere(self, n):
16421642
r"""
16431643
A `\Delta`-complex representation of the `n`-dimensional sphere,
16441644
formed by gluing two `n`-simplices along their boundary,
@@ -1653,9 +1653,8 @@ def Sphere(self,n):
16531653
Vector space of dimension 1 over Finite Field of size 3
16541654
"""
16551655
if n == 1:
1656-
return DeltaComplex([ [()], [(0, 0)] ])
1657-
else:
1658-
return DeltaComplex({Simplex(n): True, Simplex(range(1,n+2)): Simplex(n)})
1656+
return DeltaComplex([[()], [(0, 0)]])
1657+
return DeltaComplex({Simplex(n): True, Simplex(range(1, n+2)): Simplex(n)})
16591658

16601659
def Torus(self):
16611660
r"""

0 commit comments

Comments
 (0)