Skip to content

Commit 5f8f5a7

Browse files
author
Release Manager
committed
sagemathgh-41179: some fixes for ruff C4 some changes suggested by ruff about using comprehension instead of list(...) ### 📝 Checklist - [ ] The title is concise and informative. - [ ] The description explains in detail what this PR is about. URL: sagemath#41179 Reported by: Frédéric Chapoton Reviewer(s):
2 parents f1ac539 + ba3d63d commit 5f8f5a7

File tree

14 files changed

+36
-35
lines changed

14 files changed

+36
-35
lines changed

src/sage/combinat/crystals/tensor_product.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,9 @@ def __classcall_private__(cls, cartan_type, shapes=None, shape=None):
965965
raise ValueError("shapes should all be partitions")
966966
S = CrystalOfSpins(cartan_type)
967967
B = CrystalOfTableaux(cartan_type, shapes=shapes)
968-
T = TensorProductOfCrystals(S, B, generators=[[S.module_generators[0],x] for x in B.module_generators])
969-
T.rename("The crystal of tableaux of type %s and shape(s) %s" % (cartan_type, list(list(shape) for shape in spin_shapes)))
968+
T = TensorProductOfCrystals(S, B, generators=[[S.module_generators[0], x] for x in B.module_generators])
969+
T.rename("The crystal of tableaux of type %s and shape(s) %s" %
970+
(cartan_type, [list(shape) for shape in spin_shapes]))
970971
T.shapes = spin_shapes
971972
return T
972973

@@ -987,13 +988,14 @@ def __init__(self, cartan_type, shapes):
987988
sage: T = crystals.Tableaux(['A',3], shape = [2,2])
988989
sage: TestSuite(T).run()
989990
"""
990-
# super().__init__(category = FiniteEnumeratedSets())
991+
# super().__init__(category = FiniteEnumeratedSets())
991992
Parent.__init__(self, category=ClassicalCrystals())
992993
self.letters = CrystalOfLetters(cartan_type)
993994
self.shapes = shapes
994-
self.module_generators = tuple(self.module_generator(la) for la in shapes)
995+
self.module_generators = tuple(self.module_generator(la)
996+
for la in shapes)
995997
self.rename("The crystal of tableaux of type %s and shape(s) %s"
996-
% (cartan_type, list(list(shape) for shape in shapes)))
998+
% (cartan_type, [list(shape) for shape in shapes]))
997999

9981000
def cartan_type(self):
9991001
"""

src/sage/combinat/recognizable_series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,8 +1842,8 @@ def _an_element_(self):
18421842
z = self.coefficient_ring().zero()
18431843
o = self.coefficient_ring().one()
18441844
e = self.coefficient_ring().an_element()
1845-
return self(list(Matrix([[o, z], [i * o, o]])
1846-
for i, _ in enumerate(self.alphabet())),
1845+
return self([Matrix([[o, z], [i * o, o]])
1846+
for i, _ in enumerate(self.alphabet())],
18471847
vector([z, e]), right=vector([e, z]))
18481848

18491849
def some_elements(self, **kwds):

src/sage/combinat/regular_sequence.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,10 @@ def linear_representation_morphism_recurrence_order_1(C, D):
11001100
Z = zero_matrix(C[0].dimensions()[0])
11011101

11021102
def blocks(r):
1103-
upper = list([C[s], D[s], Z]
1104-
for s in reversed(srange(max(0, r-2), r+1)))
1105-
lower = list([Z, C[s], D[s]]
1106-
for s in reversed(srange(k-3+len(upper), k)))
1103+
upper = [[C[s], D[s], Z]
1104+
for s in reversed(srange(max(0, r-2), r+1))]
1105+
lower = [[Z, C[s], D[s]]
1106+
for s in reversed(srange(k-3+len(upper), k))]
11071107
return upper + lower
11081108

11091109
return {r: Matrix.block(blocks(r)) for r in P.alphabet()}

src/sage/combinat/regular_sequence_bounded.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,11 @@ def make_positive(matrices) -> list:
392392
def do(mat):
393393
if is_non_negative(mat):
394394
return mat
395-
elif is_non_negative(-mat):
395+
if is_non_negative(-mat):
396396
return -mat
397-
else:
398-
raise ValueError('There is a matrix which is neither non-negative nor non-positive.')
397+
raise ValueError('There is a matrix which is neither non-negative nor non-positive.')
399398

400-
return list(do(mat) for mat in matrices)
399+
return [do(mat) for mat in matrices]
401400

402401

403402
def regular_sequence_is_bounded(S):
@@ -521,8 +520,8 @@ def regular_sequence_is_bounded(S):
521520
if not has_bounded_matrix_powers(matrices):
522521
return False
523522

524-
matricesProd = list(ell * em for ell in matrices for em in matrices
525-
if ell != em)
523+
matricesProd = [ell * em for ell in matrices for em in matrices
524+
if ell != em]
526525
if not has_bounded_matrix_powers(matricesProd):
527526
return False
528527

src/sage/combinat/skew_tableau.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ def __eq__(self, other):
175175
"""
176176
if isinstance(other, (Tableau, SkewTableau)):
177177
return list(self) == list(other)
178-
else:
179-
return list(self) == other or list(list(row) for row in self) == other
178+
return list(self) == other or [list(row) for row in self] == other
180179

181180
def __ne__(self, other):
182181
r"""

src/sage/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,6 @@ def sage_data_paths(name: str = '') -> set[str]:
519519
for path in site_data_dir("sagemath", multipath=True).split(os.pathsep) + site_data_dir(multipath=True).split(os.pathsep):
520520
paths.add(path)
521521
else:
522-
paths = {path for path in SAGE_DATA_PATH.split(os.pathsep)}
522+
paths = set(SAGE_DATA_PATH.split(os.pathsep))
523523

524524
return {os.path.join(path, name) for path in paths if os.path.exists(path)}

src/sage/geometry/polyhedron/base5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,11 +1907,11 @@ def linear_transformation(self, linear_transf,
19071907
new_lines = ()
19081908

19091909
if self.is_compact() and self.n_vertices() and self.n_inequalities():
1910-
homogeneous_basis = matrix(R, ( [1] + list(v) for v in self.an_affine_basis() )).transpose()
1910+
homogeneous_basis = matrix(R, ([1] + list(v) for v in self.an_affine_basis())).transpose()
19111911

19121912
# To convert first to a list and then to a matrix seems to be necessary to obtain a meaningful error,
19131913
# in case the number of columns doesn't match the dimension.
1914-
new_homogeneous_basis = matrix(list( [1] + list(linear_transf*vector(R, v)) for v in self.an_affine_basis()) ).transpose()
1914+
new_homogeneous_basis = matrix([[1] + list(linear_transf*vector(R, v)) for v in self.an_affine_basis()]).transpose()
19151915

19161916
if self.dim() + 1 == new_homogeneous_basis.rank():
19171917
# The transformation is injective on the polytope.

src/sage/geometry/polyhedron/generating_function.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ def key(t):
684684
return (-sum(abs(d) for d in D), D)
685685
terms = sorted(terms, key=key, reverse=True)
686686
return Factorization([(numerator, 1)] +
687-
list((1-t, -1) for t in terms),
687+
[(1 - t, -1) for t in terms],
688688
sort=Factorization_sort,
689689
simplify=Factorization_simplify)
690690

@@ -1178,8 +1178,8 @@ def _transform_(self):
11781178
inequalities_extra.append(tuple(coeffs))
11791179
T = matrix(ZZ, dim, dim, D)
11801180

1181-
self.inequalities = (list(tuple(T*vector(ieq))
1182-
for ieq in inequalities_filtered)
1181+
self.inequalities = ([tuple(T * vector(ieq))
1182+
for ieq in inequalities_filtered]
11831183
+ inequalities_extra)
11841184

11851185
rules_pre = ((y, B({tuple(row[1:]): 1}))
@@ -1465,8 +1465,8 @@ def _transform_(self):
14651465
self.factor = next(rules_pre)[1]
14661466
self.rules = dict(rules_pre)
14671467

1468-
self.inequalities = list(tuple(vector(e)*T) for e in self.inequalities)
1469-
self.equations = list(tuple(vector(e)*T) for e in self.equations)
1468+
self.inequalities = [tuple(vector(e) * T) for e in self.inequalities]
1469+
self.equations = [tuple(vector(e) * T) for e in self.equations]
14701470

14711471
@staticmethod
14721472
def generate_mods(equations):

src/sage/geometry/toric_plotter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,9 @@ def label_list(label, n, math_mode, index_set=None):
833833
index_set = range(n)
834834
if math_mode:
835835
label = label.strip("$")
836-
return list("$%s_{%d}$" % (label, i) for i in index_set)
836+
return ["$%s_{%d}$" % (label, i) for i in index_set]
837837
else:
838-
return list("%s_%d" % (label, i) for i in index_set)
838+
return ["%s_%d" % (label, i) for i in index_set]
839839

840840

841841
def options(option=None, **kwds):

src/sage/graphs/generators/families.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3131,7 +3131,7 @@ def next_step(triangle_list):
31313131
resu += [(a, ab, ac), (ab, b, bc), (ac, bc, c)]
31323132
return resu
31333133

3134-
tri_list = [list(vector(QQ, u) for u in [(0, 0), (0, 1), (1, 0)])]
3134+
tri_list = [[vector(QQ, u) for u in [(0, 0), (0, 1), (1, 0)]]]
31353135
for k in range(n - 1):
31363136
tri_list = next_step(tri_list)
31373137
dg = Graph()

0 commit comments

Comments
 (0)