Skip to content

Commit 153864b

Browse files
author
Release Manager
committed
gh-40757: various pep8 fixes in groups/ some fixes about pep8 E2** in groups ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40757 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 90d2653 + dfea80a commit 153864b

File tree

9 files changed

+187
-185
lines changed

9 files changed

+187
-185
lines changed

src/sage/groups/abelian_gps/values.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def AbelianGroupWithValues(values, n, gens_orders=None, names='f', check=False,
142142
if values_group is None:
143143
from sage.structure.sequence import Sequence
144144
values_group = Sequence(values).universe()
145-
values = tuple( values_group(val) for val in values )
146-
M = AbelianGroupWithValues_class(gens_orders, names, values, values_group)
147-
return M
145+
values = tuple(values_group(val) for val in values)
146+
return AbelianGroupWithValues_class(gens_orders, names,
147+
values, values_group)
148148

149149

150150
class AbelianGroupWithValuesEmbedding(Morphism):
@@ -264,7 +264,7 @@ def value(self):
264264
"""
265265
if self._value is None:
266266
values = self.parent().gens_values()
267-
self._value = prod( v**e for v,e in zip(values, self.exponents()) )
267+
self._value = prod(v**e for v, e in zip(values, self.exponents()))
268268
return self._value
269269

270270
def _div_(left, right):

src/sage/groups/conjugacy_classes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
sage: TestSuite(C).run()
4848
"""
4949

50-
#****************************************************************************
50+
# **************************************************************************
5151
# Copyright (C) 2011 Javier López Peña <[email protected]>
5252
#
5353
# Distributed under the terms of the GNU General Public License (GPL)
54-
# http://www.gnu.org/licenses/
55-
#****************************************************************************
54+
# https://www.gnu.org/licenses/
55+
# **************************************************************************
5656

5757
from sage.structure.parent import Parent
5858
from sage.misc.cachefunc import cached_method

src/sage/groups/cubic_braid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def __init__(self, names, cbg_type=None):
802802
self._centralizing_matrix = None # for Assion groups: element in classical base group commuting with self
803803
self._centralizing_element = None # image under nat. map of the former one in the proj. classical group
804804

805-
def _repr_(self):
805+
def _repr_(self) -> str:
806806
r"""
807807
Return a string representation.
808808
@@ -815,8 +815,8 @@ def _repr_(self):
815815
"""
816816
if self._cbg_type == CubicBraidGroup.type.Coxeter:
817817
return "Cubic Braid group on %s strands" % (self.strands())
818-
else:
819-
return "Assion group on %s strands of type %s" % (self.strands() ,self._cbg_type.value)
818+
return "Assion group on %s strands of type %s" % (self.strands(),
819+
self._cbg_type.value)
820820

821821
def index_set(self):
822822
r"""

src/sage/groups/finitely_presented_named.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
from sage.rings.integer_ring import ZZ
7272

7373

74-
def CyclicPresentation(n):
74+
def CyclicPresentation(n) -> FinitelyPresentedGroup:
7575
r"""
7676
Build cyclic group of order `n` as a finitely presented group.
7777
@@ -195,15 +195,18 @@ def FinitelyGeneratedAbelianPresentation(int_list):
195195
invariants = FGP_Module(ZZ**(len(int_list)), col_sp).invariants()
196196
name_gen = _lexi_gen()
197197
F = FreeGroup([next(name_gen) for i in invariants])
198-
ret_rls = [F([i+1])**invariants[i] for i in range(len(invariants)) if invariants[i] != 0]
198+
ret_rls = [F([i + 1])**invariants[i] for i in range(len(invariants))
199+
if invariants[i] != 0]
199200

200201
# Build commutator relations
201-
gen_pairs = [[F.gen(i),F.gen(j)] for i in range(F.ngens()-1) for j in range(i+1,F.ngens())]
202-
ret_rls = ret_rls + [x[0]**(-1)*x[1]**(-1)*x[0]*x[1] for x in gen_pairs]
202+
gen_pairs = [[F.gen(i), F.gen(j)] for i in range(F.ngens() - 1)
203+
for j in range(i + 1, F.ngens())]
204+
ret_rls = ret_rls + [x[0]**(-1) * x[1]**(-1) * x[0] * x[1]
205+
for x in gen_pairs]
203206
return FinitelyPresentedGroup(F, tuple(ret_rls))
204207

205208

206-
def FinitelyGeneratedHeisenbergPresentation(n=1, p=0):
209+
def FinitelyGeneratedHeisenbergPresentation(n=1, p=0) -> FinitelyPresentedGroup:
207210
r"""
208211
Return a finite presentation of the Heisenberg group.
209212
@@ -265,14 +268,14 @@ def FinitelyGeneratedHeisenbergPresentation(n=1, p=0):
265268
raise ValueError('n must be a positive integer')
266269

267270
# generators' names are x1, .., xn, y1, .., yn, z
268-
vx = ['x' + str(i) for i in range(1,n+1)]
269-
vy = ['y' + str(i) for i in range(1,n+1)]
271+
vx = ['x' + str(i) for i in range(1, n + 1)]
272+
vy = ['y' + str(i) for i in range(1, n + 1)]
270273
str_generators = ', '.join(vx + vy + ['z'])
271274

272275
F = FreeGroup(str_generators)
273-
x = F.gens()[0:n] # list of generators x1, x2, ..., xn
274-
y = F.gens()[n:2*n] # list of generators x1, x2, ..., xn
275-
z = F.gen(n*2)
276+
x = F.gens()[0:n] # list of generators x1, x2, ..., xn
277+
y = F.gens()[n:2 * n] # list of generators x1, x2, ..., xn
278+
z = F.gen(n * 2)
276279

277280
def commutator(a, b):
278281
return a * b * a**-1 * b**-1
@@ -294,7 +297,7 @@ def commutator(a, b):
294297
return FinitelyPresentedGroup(F, tuple(rls))
295298

296299

297-
def DihedralPresentation(n):
300+
def DihedralPresentation(n) -> FinitelyPresentedGroup:
298301
r"""
299302
Build the Dihedral group of order `2n` as a finitely presented group.
300303
@@ -322,15 +325,15 @@ def DihedralPresentation(n):
322325
...
323326
ValueError: finitely presented group order must be positive
324327
"""
325-
n = Integer( n )
328+
n = Integer(n)
326329
if n < 1:
327330
raise ValueError('finitely presented group order must be positive')
328-
F = FreeGroup([ 'a', 'b' ])
329-
rls = F([1])**n, F([2])**2, (F([1])*F([2]))**2
330-
return FinitelyPresentedGroup( F, rls )
331+
F = FreeGroup(['a', 'b'])
332+
rls = F([1])**n, F([2])**2, (F([1]) * F([2]))**2
333+
return FinitelyPresentedGroup(F, rls)
331334

332335

333-
def DiCyclicPresentation(n):
336+
def DiCyclicPresentation(n) -> FinitelyPresentedGroup:
334337
r"""
335338
Build the dicyclic group of order `4n`, for `n \geq 2`, as a finitely
336339
presented group.
@@ -376,12 +379,12 @@ def DiCyclicPresentation(n):
376379
if n < 2:
377380
raise ValueError('input integer must be greater than 1')
378381

379-
F = FreeGroup(['a','b'])
380-
rls = F([1])**(2*n), F([2,2])*F([-1])**n, F([-2,1,2,1])
382+
F = FreeGroup(['a', 'b'])
383+
rls = F([1])**(2 * n), F([2, 2]) * F([-1])**n, F([-2, 1, 2, 1])
381384
return FinitelyPresentedGroup(F, rls)
382385

383386

384-
def SymmetricPresentation(n):
387+
def SymmetricPresentation(n) -> FinitelyPresentedGroup:
385388
r"""
386389
Build the Symmetric group of order `n!` as a finitely presented group.
387390
@@ -432,7 +435,7 @@ def SymmetricPresentation(n):
432435
return FinitelyPresentedGroup(F, ret_rls)
433436

434437

435-
def QuaternionPresentation():
438+
def QuaternionPresentation() -> FinitelyPresentedGroup:
436439
r"""
437440
Build the Quaternion group of order 8 as a finitely presented group.
438441
@@ -453,12 +456,12 @@ def QuaternionPresentation():
453456
sage: Q.is_isomorphic(groups.presentation.DiCyclic(2))
454457
True
455458
"""
456-
F = FreeGroup(['a','b'])
457-
rls = F([1])**4, F([2,2,-1,-1]), F([1,2,1,-2])
459+
F = FreeGroup(['a', 'b'])
460+
rls = F([1])**4, F([2, 2, -1, -1]), F([1, 2, 1, -2])
458461
return FinitelyPresentedGroup(F, rls)
459462

460463

461-
def AlternatingPresentation(n):
464+
def AlternatingPresentation(n) -> FinitelyPresentedGroup:
462465
r"""
463466
Build the Alternating group of order `n!/2` as a finitely presented group.
464467
@@ -509,7 +512,7 @@ def AlternatingPresentation(n):
509512
return FinitelyPresentedGroup(F, ret_rls)
510513

511514

512-
def KleinFourPresentation():
515+
def KleinFourPresentation() -> FinitelyPresentedGroup:
513516
r"""
514517
Build the Klein group of order `4` as a finitely presented group.
515518
@@ -520,12 +523,12 @@ def KleinFourPresentation():
520523
sage: K = groups.presentation.KleinFour(); K
521524
Finitely presented group < a, b | a^2, b^2, a^-1*b^-1*a*b >
522525
"""
523-
F = FreeGroup(['a','b'])
524-
rls = F([1])**2, F([2])**2, F([-1])*F([-2])*F([1])*F([2])
526+
F = FreeGroup(['a', 'b'])
527+
rls = F([1])**2, F([2])**2, F([-1]) * F([-2]) * F([1]) * F([2])
525528
return FinitelyPresentedGroup(F, rls)
526529

527530

528-
def BinaryDihedralPresentation(n):
531+
def BinaryDihedralPresentation(n) -> FinitelyPresentedGroup:
529532
r"""
530533
Build a binary dihedral group of order `4n` as a finitely presented group.
531534
@@ -555,12 +558,12 @@ def BinaryDihedralPresentation(n):
555558
....: assert P.is_isomorphic(M)
556559
"""
557560
F = FreeGroup('x,y,z')
558-
x,y,z = F.gens()
559-
rls = (x**-2 * y**2, x**-2 * z**n, x**-2 * x*y*z)
561+
x, y, z = F.gens()
562+
rls = (x**-2 * y**2, x**-2 * z**n, x**-2 * x * y * z)
560563
return FinitelyPresentedGroup(F, rls)
561564

562565

563-
def CactusPresentation(n):
566+
def CactusPresentation(n) -> FinitelyPresentedGroup:
564567
r"""
565568
Build the `n`-fruit cactus group as a finitely presented group.
566569
@@ -579,11 +582,11 @@ def CactusPresentation(n):
579582
rls = [g**2 for g in gens]
580583
Gg = G.group_generators()
581584
K = Gg.keys()
582-
for i,key in enumerate(K):
583-
for j,key2 in enumerate(K):
585+
for i, key in enumerate(K):
586+
for j, key2 in enumerate(K):
584587
if i == j:
585588
continue
586-
x,y = (Gg[key] * Gg[key2])._data
589+
x, y = (Gg[key] * Gg[key2])._data
587590
if key == x and key2 == y:
588591
continue
589592
elt = gens[i] * gens[j] * ~gens[K.index(y)] * ~gens[K.index(x)]

src/sage/groups/indexed_free_group.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def __invert__(self):
280280
return self.__class__(self.parent(),
281281
tuple((x[0], -x[1]) for x in reversed(self._monomial)))
282282

283-
def to_word_list(self):
283+
def to_word_list(self) -> list[tuple]:
284284
"""
285285
Return ``self`` as a word represented as a list whose entries
286286
are the pairs ``(i, s)`` where ``i`` is the index and ``s`` is
@@ -294,9 +294,8 @@ def to_word_list(self):
294294
sage: x.to_word_list()
295295
[(0, 1), (1, 1), (1, 1), (4, 1), (0, -1)]
296296
"""
297-
sign = lambda x: 1 if x > 0 else -1 # It is never 0
298-
return [ (k, sign(e)) for k,e in self._sorted_items()
299-
for dummy in range(abs(e))]
297+
return [(k, 1 if e > 0 else -1) for k, e in self._sorted_items()
298+
for dummy in range(abs(e))]
300299

301300

302301
class IndexedFreeAbelianGroup(IndexedGroup, AbelianGroup):

src/sage/groups/libgap_morphism.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def lift(self, h):
515515
phi = self.gap()
516516
if h.gap() not in phi.Image():
517517
raise ValueError("{} is not an element of the image of {}".format(h, self))
518-
return self.domain()( phi.PreImagesRepresentative(h.gap()) )
518+
return self.domain()(phi.PreImagesRepresentative(h.gap()))
519519

520520
def preimage(self, S):
521521
r"""

src/sage/groups/matrix_gps/heisenberg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
- Hilder Vitor Lima Pereira (2017-08): initial version
88
"""
99

10-
#*****************************************************************************
10+
# ***************************************************************************
1111
# Copyright (C) 2017 Hilder Vitor Lima Pereira <hilder.vitor at gmail.com>
1212
#
1313
# This program is free software: you can redistribute it and/or modify
1414
# it under the terms of the GNU General Public License as published by
1515
# the Free Software Foundation, either version 2 of the License, or
1616
# (at your option) any later version.
17-
# http://www.gnu.org/licenses/
18-
#*****************************************************************************
17+
# https://www.gnu.org/licenses/
18+
# ***************************************************************************
1919

2020
from sage.groups.matrix_gps.finitely_generated_gap import FinitelyGeneratedMatrixGroup_gap
2121
from sage.structure.unique_representation import UniqueRepresentation

0 commit comments

Comments
 (0)