Skip to content

Commit 09902fd

Browse files
committed
some fixes for ruff C4
1 parent e0cf1e4 commit 09902fd

File tree

13 files changed

+51
-50
lines changed

13 files changed

+51
-50
lines changed

src/sage/algebras/free_algebra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ def merge(self, other):
16701670
o_degs = [1] * len(other.vars)
16711671
else:
16721672
o_degs = list(other.degs)
1673-
self_table = {w: d for w, d in zip(self.vars, deg)}
1673+
self_table = dict(zip(self.vars, deg))
16741674
for v, d in zip(other.vars, o_degs):
16751675
if v not in self_vars:
16761676
deg.append(d)

src/sage/combinat/root_system/ambient_space.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def __call__(self, v):
193193
# This adds coercion from a list
194194
if isinstance(v, (list, tuple)):
195195
K = self.base_ring()
196-
return self._from_dict(dict((i,K(c)) for i,c in enumerate(v) if c))
196+
return self._from_dict({i: K(c) for i, c in enumerate(v) if c})
197197
else:
198198
return CombinatorialFreeModule.__call__(self, v)
199199

src/sage/combinat/root_system/cartan_type.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,10 +1739,10 @@ def symmetrizer(self):
17391739
from sage.matrix.constructor import matrix, diagonal_matrix
17401740
m = self.cartan_matrix()
17411741
n = m.nrows()
1742-
M = matrix(ZZ, n, n*n, sparse=True)
1743-
for (i,j) in m.nonzero_positions():
1744-
M[i, n * i + j] = m[i,j]
1745-
M[j, n * i + j] -= m[j,i]
1742+
M = matrix(ZZ, n, n * n, sparse=True)
1743+
for i, j in m.nonzero_positions():
1744+
M[i, n * i + j] = m[i, j]
1745+
M[j, n * i + j] -= m[j, i]
17461746
kern = M.integer_kernel()
17471747
c = len(self.dynkin_diagram().connected_components(sort=False))
17481748
if kern.dimension() < c:
@@ -1757,7 +1757,7 @@ def symmetrizer(self):
17571757
D = sum(kern.basis())
17581758
assert diagonal_matrix(D) * m == m.transpose() * diagonal_matrix(D)
17591759
I = self.index_set()
1760-
return Family( dict( (I[i], D[i]) for i in range(n) ) )
1760+
return Family({I[i]: D[i] for i in range(n)})
17611761

17621762
def index_set_bipartition(self):
17631763
r"""
@@ -2131,7 +2131,7 @@ def row_annihilator(self, m=None):
21312131
raise ValueError("the kernel is not 1 dimensional")
21322132
assert (all(coef > 0 for coef in annihilator_basis[0]))
21332133

2134-
return Family(dict((i,annihilator_basis[0][i])for i in self.index_set()))
2134+
return Family({i: annihilator_basis[0][i] for i in self.index_set()})
21352135

21362136
acheck = row_annihilator
21372137

@@ -2205,8 +2205,8 @@ def c(self):
22052205
"""
22062206
a = self.a()
22072207
acheck = self.acheck()
2208-
return Family(dict((i, max(ZZ(1), a[i] // acheck[i]))
2209-
for i in self.index_set()))
2208+
return Family({i: max(ZZ.one(), a[i] // acheck[i])
2209+
for i in self.index_set()})
22102210

22112211
def translation_factors(self):
22122212
r"""
@@ -2372,21 +2372,21 @@ def translation_factors(self):
23722372
23732373
REFERENCES:
23742374
2375-
.. [HST09] \F. Hivert, A. Schilling, and N. M. Thiery,
2375+
.. [HST09] \F. Hivert, A. Schilling, and N. M. Thiéry,
23762376
*Hecke group algebras as quotients of affine Hecke
23772377
algebras at level 0*, JCT A, Vol. 116, (2009) p. 844-863
23782378
:arxiv:`0804.3781`
23792379
"""
23802380
a = self.a()
23812381
acheck = self.acheck()
2382-
if set([1/ZZ(2), 2]).issubset( set(a[i]/acheck[i] for i in self.index_set()) ):
2382+
s = set(a[i] / acheck[i] for i in self.index_set())
2383+
if ~ZZ(2) in s and 2 in s:
23832384
# The test above and the formula below are rather meaningless
23842385
# But they detect properly type BC or dual and return the correct value
2385-
return Family(dict((i, min(ZZ(1), a[i] / acheck[i]))
2386-
for i in self.index_set()))
2386+
return Family({i: min(ZZ.one(), a[i] / acheck[i])
2387+
for i in self.index_set()})
23872388

2388-
else:
2389-
return self.c()
2389+
return self.c()
23902390

23912391
def _test_dual_classical(self, **options):
23922392
r"""

src/sage/combinat/root_system/type_folded.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def f(i):
292292
return root.leading_coefficient() / coroot.leading_coefficient()
293293
index_set = self._cartan_type.index_set()
294294
min_f = min(f(j) for j in index_set)
295-
return Family(dict( (i, int(f(i) / min_f)) for i in index_set ))
295+
return Family({i: int(f(i) / min_f) for i in index_set})
296296
elif self._cartan_type.is_affine():
297297
c = self._cartan_type.translation_factors()
298298
cmax = max(c)
299-
return Family(dict( (i, int(cmax / c[i]))
300-
for i in self._cartan_type.index_set() ))
299+
return Family({i: int(cmax / c[i])
300+
for i in self._cartan_type.index_set()})

src/sage/combinat/root_system/type_reducible.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ def __init__(self, types):
116116
"""
117117
self._types = types
118118
self.affine = False
119-
indices = (None,) + tuple( (i, j)
120-
for i in range(len(types))
121-
for j in types[i].index_set() )
119+
indices = (None,) + tuple((i, j)
120+
for i in range(len(types))
121+
for j in types[i].index_set())
122122
self._indices = indices
123-
self._index_relabelling = dict((indices[i], i) for i in range(1, len(indices)))
123+
self._index_relabelling = {indices[i]: i
124+
for i in range(1, len(indices))}
124125

125126
self._spaces = [t.root_system().ambient_space() for t in types]
126127
if all(l is not None for l in self._spaces):
@@ -130,9 +131,9 @@ def __init__(self, types):
130131
self.tools = root_system.type_reducible
131132
# a direct product of finite Cartan types is again finite;
132133
# idem for simply laced and crystallographic.
133-
super_classes = tuple( cls
134-
for cls in (CartanType_finite, CartanType_simply_laced, CartanType_crystallographic)
135-
if all(isinstance(t, cls) for t in types) )
134+
super_classes = tuple(cls
135+
for cls in (CartanType_finite, CartanType_simply_laced, CartanType_crystallographic)
136+
if all(isinstance(t, cls) for t in types))
136137
self._add_abstract_superclass(super_classes)
137138

138139
def _repr_(self, compact=True): # We should make a consistent choice here

src/sage/combinat/root_system/weight_lattice_realizations.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,10 @@ def dynkin_diagram_automorphism_of_alcove_morphism(self, f):
596596
# Now, we have d = f w^-1
597597
winv = ~w
598598
assert all(alpha[i].level().is_zero() for i in self.index_set())
599-
rank_simple_roots = dict( (alpha[i],i) for i in self.index_set())
599+
rank_simple_roots = {alpha[i]: i for i in self.index_set()}
600600
permutation = dict()
601601
for i in self.index_set():
602-
root = f(winv.action(alpha[i])) # This is d(alpha_i)
602+
root = f(winv.action(alpha[i])) # This is d(alpha_i)
603603
assert root in rank_simple_roots
604604
permutation[i] = rank_simple_roots[root]
605605
assert set(permutation.values()), set(self.index_set())
@@ -694,7 +694,8 @@ def _test_reduced_word_of_translation(self, elements=None, **options):
694694
# preserving the alcoves.
695695
if elements is None:
696696
c = self.cartan_type().c()
697-
elements = [ c[i] * Lambda[i] for i in self.cartan_type().classical().index_set() ]
697+
elements = [c[i] * Lambda[i]
698+
for i in self.cartan_type().classical().index_set()]
698699

699700
# When the null root is zero in this root lattice realization,
700701
# the roots correspond to the classical roots. We use that to
@@ -703,7 +704,7 @@ def _test_reduced_word_of_translation(self, elements=None, **options):
703704
# set to be of the form 0..n
704705
test_automorphism = self.null_root().is_zero() and set(self.index_set()) == set(i for i in range(len(self.index_set())))
705706
# dictionary assigning a simple root to its index
706-
rank_simple_roots = dict( (alpha[i],i) for i in self.index_set() )
707+
rank_simple_roots = {alpha[i]: i for i in self.index_set()}
707708

708709
try:
709710
W = self.weyl_group()

src/sage/combinat/similarity_class_type.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,11 @@ def number_of_classes(self, invertible=False, q=None):
919919
maximum_degree = max(list_of_degrees)
920920
numerator = prod([prod([primitives(d+1, invertible=invertible, q=q)-i for i in range(list_of_degrees.count(d+1))]) for d in range(maximum_degree)])
921921
tau_list = list(self)
922-
D = dict((i, tau_list.count(i)) for i in tau_list)
922+
D = {i: tau_list.count(i) for i in tau_list}
923923
denominator = prod(factorial(D[primary_type]) for primary_type in D)
924924
return numerator / denominator
925925

926-
def is_semisimple(self):
926+
def is_semisimple(self) -> bool:
927927
"""
928928
Return ``True`` if every primary similarity class type in ``self`` has
929929
all parts equal to ``1``.
@@ -939,7 +939,7 @@ def is_semisimple(self):
939939
"""
940940
return all(PT.partition().get_part(0) == 1 for PT in self)
941941

942-
def is_regular(self):
942+
def is_regular(self) -> bool:
943943
"""
944944
Return ``True`` if every primary type in ``self`` has partition with one
945945
part.
@@ -1325,8 +1325,9 @@ def dictionary_from_generator(gen):
13251325
high.
13261326
"""
13271327
L = list(gen)
1328-
setofkeys = list(set(item[0] for item in L))
1329-
return dict((key, sum(entry[1] for entry in (pair for pair in L if pair[0] == key))) for key in setofkeys)
1328+
setofkeys = set(item[0] for item in L)
1329+
return {key: sum(pair[1] for pair in L if pair[0] == key)
1330+
for key in setofkeys}
13301331

13311332

13321333
def matrix_similarity_classes(n, q=None, invertible=False):

src/sage/combinat/symmetric_group_algebra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,7 +2887,7 @@ def a(tableau, star=0, base_ring=QQ):
28872887
if n <= 1:
28882888
return sgalg.one()
28892889

2890-
rd = dict((P(h), one) for h in rs)
2890+
rd = {P(h): one for h in rs}
28912891
return sgalg._from_dict(rd)
28922892

28932893

@@ -2971,7 +2971,7 @@ def b(tableau, star=0, base_ring=QQ):
29712971
if n <= 1:
29722972
return sgalg.one()
29732973

2974-
cd = dict((P(v), v.sign() * one) for v in cs)
2974+
cd = {P(v): v.sign() * one for v in cs}
29752975
return sgalg._from_dict(cd)
29762976

29772977

src/sage/crypto/mq/sr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def __init__(self, n=1, r=1, c=1, e=4, star=False, **kwargs):
462462
self._reverse_variables = bool(kwargs.get("reverse_variables", True))
463463

464464
with AllowZeroInversionsContext(self):
465-
sub_byte_lookup = dict([(v, self.sub_byte(v)) for v in self._base])
465+
sub_byte_lookup = {v: self.sub_byte(v) for v in self._base}
466466
self._sub_byte_lookup = sub_byte_lookup
467467

468468
if self._gf2:

src/sage/manifolds/utilities.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,10 @@ def _repr_(self):
972972
strv[i] = "(" + sv + ")"
973973

974974
# dictionary to group multiple occurrences of differentiation: d/dxdx -> d/dx^2 etc.
975-
occ = dict((i, strv[i] + "^" + str(diffargs.count(i))
976-
if (diffargs.count(i) > 1) else strv[i])
977-
for i in diffargs)
975+
occ = {i: strv[i] + "^" + str(D) if (D := diffargs.count(i)) > 1
976+
else strv[i] for i in diffargs}
978977

979-
res = "d" + str(numargs) + "(" + str(funcname) + ")/d" + "d".join(
980-
occ.values())
978+
res = f"d{numargs}({funcname})/d" + "d".join(occ.values())
981979

982980
# str representation of the operator
983981
s = self._parent._repr_element_(m[0])

0 commit comments

Comments
 (0)