Skip to content

Commit d37ff1a

Browse files
author
Release Manager
committed
gh-39315: partial pep8 cleanup in Lie conformal algebras just adding spaces after comma, mostly alos using `.items()` in several places ### 📝 Checklist - [x] The title is concise and informative. - [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 and checked the documentation preview. URL: #39315 Reported by: Frédéric Chapoton Reviewer(s): David Coudert, Frédéric Chapoton
2 parents f2bdadf + 14d64f9 commit d37ff1a

9 files changed

+77
-67
lines changed

src/sage/algebras/lie_conformal_algebras/abelian_lie_conformal_algebra.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,17 @@ def __init__(self, R, ngens=1, weights=None,
8989
names = 'a'
9090
self._latex_names = tuple(r'a_{%d}' % i for i in range(ngens))
9191

92-
names,index_set = standardize_names_index_set(names=names,
93-
index_set=index_set,
94-
ngens=ngens)
92+
names, index_set = standardize_names_index_set(names=names,
93+
index_set=index_set,
94+
ngens=ngens)
9595
abeliandict = {}
9696

9797
GradedLieConformalAlgebra.__init__(self, R, abeliandict, names=names,
98-
index_set=index_set, weights=weights,
98+
index_set=index_set,
99+
weights=weights,
99100
parity=parity)
100101

101-
def _repr_(self):
102+
def _repr_(self) -> str:
102103
"""
103104
String representation.
104105

src/sage/algebras/lie_conformal_algebras/affine_lie_conformal_algebra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def cartan_type(self):
142142
"""
143143
return self._ct
144144

145-
def _repr_(self):
145+
def _repr_(self) -> str:
146146
"""
147147
The name of this Lie conformal algebra.
148148
@@ -152,4 +152,4 @@ def _repr_(self):
152152
The affine Lie conformal algebra of type ['A', 1] over Rational Field
153153
"""
154154
return "The affine Lie conformal algebra of type {} over {}".format(
155-
self._ct,self.base_ring())
155+
self._ct, self.base_ring())

src/sage/algebras/lie_conformal_algebras/bosonic_ghosts_lie_conformal_algebra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(self, R, ngens=2, names=None, index_set=None):
120120
weights=weights,
121121
central_elements=('K',))
122122

123-
def _repr_(self):
123+
def _repr_(self) -> str:
124124
"""
125125
String representation.
126126
@@ -130,4 +130,4 @@ def _repr_(self):
130130
The Bosonic ghosts Lie conformal algebra with generators (beta, gamma, K) over Algebraic Field
131131
"""
132132
return "The Bosonic ghosts Lie conformal algebra with generators {} "\
133-
"over {}".format(self.gens(),self.base_ring())
133+
"over {}".format(self.gens(), self.base_ring())

src/sage/algebras/lie_conformal_algebras/fermionic_ghosts_lie_conformal_algebra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __init__(self, R, ngens=2, names=None, index_set=None):
117117
parity=parity,
118118
central_elements=('K',))
119119

120-
def _repr_(self):
120+
def _repr_(self) -> str:
121121
"""
122122
String representation.
123123
@@ -127,4 +127,4 @@ def _repr_(self):
127127
The Fermionic ghosts Lie conformal algebra with generators (b, c, K) over Rational Field
128128
"""
129129
return "The Fermionic ghosts Lie conformal algebra with generators {} "\
130-
"over {}".format(self.gens(),self.base_ring())
130+
"over {}".format(self.gens(), self.base_ring())

src/sage/algebras/lie_conformal_algebras/free_bosons_lie_conformal_algebra.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,37 +114,39 @@ def __init__(self, R, ngens=None, gram_matrix=None, names=None,
114114
if ngens is None:
115115
ngens = gram_matrix.dimensions()[0]
116116
try:
117-
assert (gram_matrix in MatrixSpace(R,ngens,ngens))
117+
assert (gram_matrix in MatrixSpace(R, ngens, ngens))
118118
except AssertionError:
119119
raise ValueError("the gram_matrix should be a symmetric " +
120-
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
120+
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
121121
if not gram_matrix.is_symmetric():
122122
raise ValueError("the gram_matrix should be a symmetric " +
123-
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
123+
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
124124
else:
125125
if ngens is None:
126126
ngens = 1
127127
gram_matrix = identity_matrix(R, ngens, ngens)
128128

129129
latex_names = None
130-
if (names is None) and (index_set is None):
130+
if names is None and index_set is None:
131131
names = 'alpha'
132132
latex_names = tuple(r'\alpha_{%d}' % i
133133
for i in range(ngens)) + ('K',)
134-
names,index_set = standardize_names_index_set(names=names,
135-
index_set=index_set,
136-
ngens=ngens)
137-
bosondict = {(i,j): {1: {('K',0): gram_matrix[index_set.rank(i),
138-
index_set.rank(j)]}} for i in index_set for j in index_set}
139-
140-
GradedLieConformalAlgebra.__init__(self,R,bosondict,names=names,
134+
names, index_set = standardize_names_index_set(names=names,
135+
index_set=index_set,
136+
ngens=ngens)
137+
bosondict = {(i, j): {1: {('K', 0): gram_matrix[index_set.rank(i),
138+
index_set.rank(j)]}}
139+
for i in index_set for j in index_set}
140+
141+
GradedLieConformalAlgebra.__init__(self, R, bosondict,
142+
names=names,
141143
latex_names=latex_names,
142144
index_set=index_set,
143145
central_elements=('K',))
144146

145147
self._gram_matrix = gram_matrix
146148

147-
def _repr_(self):
149+
def _repr_(self) -> str:
148150
"""
149151
String representation.
150152
@@ -154,7 +156,7 @@ def _repr_(self):
154156
The free Bosons Lie conformal algebra with generators (alpha, K) over Algebraic Real Field
155157
"""
156158
return "The free Bosons Lie conformal algebra with generators {}"\
157-
" over {}".format(self.gens(),self.base_ring())
159+
" over {}".format(self.gens(), self.base_ring())
158160

159161
def gram_matrix(self):
160162
r"""

src/sage/algebras/lie_conformal_algebras/free_fermions_lie_conformal_algebra.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,52 +94,51 @@ def __init__(self, R, ngens=None, gram_matrix=None, names=None,
9494
"""
9595
from sage.matrix.matrix_space import MatrixSpace
9696
from sage.matrix.special import identity_matrix
97-
if (gram_matrix is not None):
97+
if gram_matrix is not None:
9898
if ngens is None:
9999
ngens = gram_matrix.dimensions()[0]
100100
try:
101-
assert (gram_matrix in MatrixSpace(R,ngens,ngens))
101+
assert (gram_matrix in MatrixSpace(R, ngens, ngens))
102102
except AssertionError:
103103
raise ValueError("The gram_matrix should be a symmetric " +
104-
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
104+
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
105105
if not gram_matrix.is_symmetric():
106106
raise ValueError("The gram_matrix should be a symmetric " +
107-
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
107+
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
108108
else:
109109
if ngens is None:
110110
ngens = 1
111111
gram_matrix = identity_matrix(R, ngens, ngens)
112112

113113
latex_names = None
114114

115-
if (names is None) and (index_set is None):
116-
if ngens == 1:
117-
names = 'psi'
118-
else:
119-
names = 'psi_'
115+
if names is None and index_set is None:
116+
names = 'psi' if ngens == 1 else 'psi_'
120117
latex_names = tuple(r"\psi_{%d}" % i
121118
for i in range(ngens)) + ('K',)
122119

123120
from sage.structure.indexed_generators import \
124-
standardize_names_index_set
125-
names,index_set = standardize_names_index_set(names=names,
126-
index_set=index_set,
127-
ngens=ngens)
128-
fermiondict = {(i,j): {0: {('K', 0): gram_matrix[index_set.rank(i),
129-
index_set.rank(j)]}} for i in index_set for j in index_set}
121+
standardize_names_index_set
122+
names, index_set = standardize_names_index_set(names=names,
123+
index_set=index_set,
124+
ngens=ngens)
125+
fermiondict = {(i, j): {0: {('K', 0): gram_matrix[index_set.rank(i),
126+
index_set.rank(j)]}}
127+
for i in index_set for j in index_set}
130128

131129
from sage.rings.rational_field import QQ
132-
weights = (QQ(1/2),)*ngens
133-
parity = (1,)*ngens
134-
GradedLieConformalAlgebra.__init__(self,R,fermiondict,names=names,
130+
weights = (QQ((1, 2)),) * ngens
131+
parity = (1,) * ngens
132+
GradedLieConformalAlgebra.__init__(self, R, fermiondict, names=names,
135133
latex_names=latex_names,
136-
index_set=index_set,weights=weights,
134+
index_set=index_set,
135+
weights=weights,
137136
parity=parity,
138137
central_elements=('K',))
139138

140139
self._gram_matrix = gram_matrix
141140

142-
def _repr_(self):
141+
def _repr_(self) -> str:
143142
"""
144143
String representation.
145144
@@ -149,8 +148,8 @@ def _repr_(self):
149148
The free Fermions super Lie conformal algebra with generators (psi, K) over Rational Field
150149
"""
151150
return "The free Fermions super Lie conformal algebra "\
152-
"with generators {} over {}".format(self.gens(),
153-
self.base_ring())
151+
"with generators {} over {}".format(self.gens(),
152+
self.base_ring())
154153

155154
def gram_matrix(self):
156155
r"""

src/sage/algebras/lie_conformal_algebras/freely_generated_lie_conformal_algebra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def lie_conformal_algebra_generators(self):
8181
(B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K'])
8282
"""
8383
F = Family(self._generators,
84-
lambda i: self.monomial((i,Integer(0))),
85-
name="generator map")
84+
lambda i: self.monomial((i, Integer(0))),
85+
name="generator map")
8686
from sage.categories.sets_cat import Sets
8787
if F in Sets().Finite():
8888
return tuple(F)

src/sage/algebras/lie_conformal_algebras/lie_conformal_algebra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def __classcall_private__(cls, R=None, arg0=None, index_set=None,
331331
if key not in known_keywords:
332332
raise ValueError("got an unexpected keyword argument '%s'" % key)
333333

334-
if isinstance(arg0,dict) and arg0:
334+
if isinstance(arg0, dict) and arg0:
335335
graded = kwds.pop("graded", False)
336336
if weights is not None or graded:
337337
from .graded_lie_conformal_algebra import \

src/sage/algebras/lie_conformal_algebras/lie_conformal_algebra_with_structure_coefs.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ class LieConformalAlgebraWithStructureCoefficients(
8787
`\lambda`-brackets of the generators::
8888
8989
sage: betagamma_dict = {('b','a'):{0:{('K',0):1}}}
90-
sage: V = LieConformalAlgebra(QQ, betagamma_dict, names=('a','b'), weights=(1,0), central_elements=('K',))
90+
sage: V = LieConformalAlgebra(QQ, betagamma_dict, names=('a','b'),
91+
....: weights=(1,0), central_elements=('K',))
9192
sage: V.category()
92-
Category of H-graded finitely generated Lie conformal algebras with basis over Rational Field
93+
Category of H-graded finitely generated Lie conformal algebras
94+
with basis over Rational Field
9395
sage: V.inject_variables()
9496
Defining a, b, K
9597
sage: a.bracket(b)
@@ -148,9 +150,8 @@ def _standardize_s_coeff(s_coeff, index_set, ce, parity=None):
148150
index_to_parity = dict(zip(index_set, parity))
149151
sc = {}
150152
# mypair has a pair of generators
151-
for mypair in s_coeff.keys():
153+
for mypair, v in s_coeff.items():
152154
# e.g. v = { 0: { (L,2):3, (G,3):1}, 1:{(L,1),2} }
153-
v = s_coeff[mypair]
154155
key = tuple(mypair)
155156
vals = {}
156157
for l in v:
@@ -186,7 +187,7 @@ def _standardize_s_coeff(s_coeff, index_set, ce, parity=None):
186187
kth_product[(i[0], i[1] + j)] = \
187188
kth_product.get((i[0], i[1] + j), 0)
188189
kth_product[(i[0], i[1] + j)] += parsgn *\
189-
v[k+j][i]*(-1)**(k+j+1)*binomial(i[1]+j,j)
190+
v[k+j][i]*(-1)**(k+j+1)*binomial(i[1]+j, j)
190191
kth_product = {k: v for k, v in kth_product.items() if v}
191192
if kth_product:
192193
vals[k] = kth_product
@@ -212,21 +213,22 @@ def __init__(self, R, s_coeff, index_set=None, central_elements=None,
212213
sage: V = lie_conformal_algebras.NeveuSchwarz(QQ)
213214
sage: TestSuite(V).run()
214215
"""
215-
names, index_set = standardize_names_index_set(names,index_set)
216+
names, index_set = standardize_names_index_set(names, index_set)
216217
if central_elements is None:
217218
central_elements = ()
218219

219220
if names is not None and names != tuple(index_set):
220221
names2 = names + tuple(central_elements)
221222
index_set2 = DisjointUnionEnumeratedSets((index_set,
222223
Family(tuple(central_elements))))
223-
d = {x:index_set2[i] for i,x in enumerate(names2)}
224+
d = {x: index_set2[i] for i, x in enumerate(names2)}
224225
try:
225-
#If we are given a dictionary with names as keys,
226-
#convert to index_set as keys
227-
s_coeff = {(d[k[0]],d[k[1]]):{a:{(d[x[1]],x[2]):
228-
s_coeff[k][a][x] for x in
229-
s_coeff[k][a]} for a in s_coeff[k]} for k in s_coeff.keys()}
226+
# If we are given a dictionary with names as keys,
227+
# convert to index_set as keys
228+
s_coeff = {(d[k[0]], d[k[1]]):
229+
{a: {(d[x[1]], x[2]): sck[a][x] for x in sck[a]}
230+
for a in s_coeff[k]}
231+
for k, sck in s_coeff.items()}
230232

231233
except KeyError:
232234
# We assume the dictionary was given with keys in the
@@ -274,9 +276,12 @@ def __init__(self, R, s_coeff, index_set=None, central_elements=None,
274276
prefix=prefix, names=names, latex_names=latex_names, **kwds)
275277

276278
s_coeff = dict(s_coeff)
277-
self._s_coeff = Family({k: tuple((j, sum(c*self.monomial(i)
278-
for i,c in v)) for j,v in s_coeff[k]) for k in s_coeff})
279-
self._parity = dict(zip(self.gens(),parity+(0,)*len(central_elements)))
279+
self._s_coeff = Family({k:
280+
tuple((j, sum(c * self.monomial(i)
281+
for i, c in v)) for j, v in sck)
282+
for k, sck in s_coeff.items()})
283+
self._parity = dict(zip(self.gens(),
284+
parity + (0,) * len(central_elements)))
280285

281286
def structure_coefficients(self):
282287
"""
@@ -289,11 +294,14 @@ def structure_coefficients(self):
289294
Finite family {('L', 'L'): ((0, TL), (1, 2*L), (3, 1/2*C))}
290295
291296
sage: lie_conformal_algebras.NeveuSchwarz(QQ).structure_coefficients()
292-
Finite family {('G', 'G'): ((0, 2*L), (2, 2/3*C)), ('G', 'L'): ((0, 1/2*TG), (1, 3/2*G)), ('L', 'G'): ((0, TG), (1, 3/2*G)), ('L', 'L'): ((0, TL), (1, 2*L), (3, 1/2*C))}
297+
Finite family {('G', 'G'): ((0, 2*L), (2, 2/3*C)),
298+
('G', 'L'): ((0, 1/2*TG), (1, 3/2*G)),
299+
('L', 'G'): ((0, TG), (1, 3/2*G)),
300+
('L', 'L'): ((0, TL), (1, 2*L), (3, 1/2*C))}
293301
"""
294302
return self._s_coeff
295303

296-
def _repr_generator(self, x):
304+
def _repr_generator(self, x) -> str:
297305
"""
298306
String representation of the generator ``x``.
299307
@@ -316,4 +324,4 @@ def _repr_generator(self, x):
316324
"""
317325
if x in self:
318326
return repr(x)
319-
return IndexedGenerators._repr_generator(self,x)
327+
return IndexedGenerators._repr_generator(self, x)

0 commit comments

Comments
 (0)