Skip to content

Commit bc5827d

Browse files
committed
some fixes for ruff SIM113
1 parent 1f45900 commit bc5827d

File tree

11 files changed

+33
-67
lines changed

11 files changed

+33
-67
lines changed

src/sage/categories/enumerated_sets.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -785,12 +785,11 @@ def _rank_from_iterator(self, x):
785785
2
786786
sage: C.rank(5) # indirect doctest
787787
"""
788-
counter = 0
789-
for u in self:
788+
for counter, u in enumerate(self):
790789
if u == x:
791790
return counter
792-
counter += 1
793791
return None
792+
794793
rank = _rank_from_iterator
795794

796795
def _iterator_from_list(self):
@@ -929,12 +928,11 @@ def _some_elements_from_iterator(self):
929928
sage: list(C.some_elements()) # indirect doctest
930929
[1, 2, 3]
931930
"""
932-
nb = 0
933-
for i in self:
931+
for nb, i in enumerate(self):
934932
yield i
935-
nb += 1
936-
if nb >= 100:
933+
if nb >= 99:
937934
break
935+
938936
some_elements = _some_elements_from_iterator
939937

940938
def random_element(self):
@@ -1045,10 +1043,8 @@ def _test_enumerated_set_contains(self, **options):
10451043
of a finite enumerated set: {1,2,3}
10461044
"""
10471045
tester = self._tester(**options)
1048-
i = 0
1049-
for w in self:
1046+
for i, w in enumerate(self, start=1):
10501047
tester.assertIn(w, self)
1051-
i += 1
10521048
if i > tester._max_runs:
10531049
return
10541050

src/sage/categories/regular_crystals.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,10 @@ def _test_stembridge_local_axioms(self, index_set=None, verbose=False, complete=
309309
"""
310310
tester = self._tester(**options)
311311
goodness = True
312-
i = 0
313-
for x in self:
312+
for i, x in enumerate(self, start=1):
314313
goodness = x._test_stembridge_local_axioms(index_set, verbose)
315314
if not goodness and not complete:
316315
tester.fail()
317-
i += 1
318316
if i > tester._max_runs:
319317
return
320318
tester.assertTrue(goodness)

src/sage/combinat/dyck_word.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,11 +926,10 @@ def _repr_svg_(self) -> str:
926926
horizontal = "<line x1=\"{}\" y1=\"{}\" x2=\"{}\" y2=\"{}\"/>"
927927
hori_lines = []
928928
path = ['<polyline points=\"0,0']
929-
x, y = 0, 0
929+
y = 0
930930
max_y = 0
931931
last_seen_level = [0]
932-
for e in self:
933-
x += 1
932+
for x, e in enumerate(self, start=1):
934933
if e == open_symbol:
935934
y += 1
936935
last_seen_level.append(x - 1)

src/sage/combinat/finite_state_machine.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4720,8 +4720,7 @@ def label_rotation(angle, both_directions):
47204720
accepting_show_empty = False
47214721

47224722
result = "\\begin{tikzpicture}[%s]\n" % ", ".join(options)
4723-
j = 0
4724-
for vertex in self.iter_states():
4723+
for j, vertex in enumerate(self.iter_states()):
47254724
if not hasattr(vertex, "coordinates"):
47264725
vertex.coordinates = (3*cos(2*pi*j/len(self.states())),
47274726
3*sin(2*pi*j/len(self.states())))
@@ -4762,8 +4761,6 @@ def label_rotation(angle, both_directions):
47624761
self.format_transition_label(vertex.final_word_out),
47634762
angle, accepting_distance)
47644763

4765-
j += 1
4766-
47674764
def key_function(s):
47684765
return (s.from_state, s.to_state)
47694766
# We use an OrderedDict instead of a dict in order to have a

src/sage/combinat/gray_codes.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,18 @@ def product(m):
6969
....: assert sum(1 for _ in product(t)) == prod(t)-1
7070
"""
7171
# n is the length of the element (we ignore sets of size 1)
72-
n = k = 0
72+
n = 0
7373

7474
new_m = [] # will be the set of upper bounds m_i different from 1
7575
mm = [] # index of each set (we skip sets of cardinality 1)
76-
for i in m:
76+
for k, i in enumerate(m):
7777
i = int(i)
7878
if i <= 0:
7979
raise ValueError("accept only positive integers")
8080
if i > 1:
81-
new_m.append(i-1)
81+
new_m.append(i - 1)
8282
mm.append(k)
8383
n += 1
84-
k += 1
8584

8685
m = new_m
8786
f = list(range(n + 1)) # focus pointer

src/sage/combinat/ncsf_qsym/qsym.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,26 +3536,20 @@ def _precompute_cache(self, n, to_self_cache, from_self_cache, transition_matric
35363536

35373537
# For every composition I of size n, expand self[I] in terms
35383538
# of the monomial basis M.
3539-
i = 0
3540-
for I in compositions_n:
3539+
for i, I in enumerate(compositions_n):
35413540
# M_coeffs will be M(self[I])._monomial_coefficients
35423541
M_coeffs = {}
35433542

35443543
self_I_in_M_basis = M.prod([from_self_gen_function(self._indices(list(J)))
35453544
for J in Word(I).lyndon_factorization()])
35463545

3547-
j = 0
3548-
3549-
for J in compositions_n:
3546+
for j, J in enumerate(compositions_n):
35503547
if J in self_I_in_M_basis._monomial_coefficients:
35513548
sp = self_I_in_M_basis._monomial_coefficients[J]
35523549
M_coeffs[J] = sp
3553-
transition_matrix_n[i,j] = sp
3554-
3555-
j += 1
3550+
transition_matrix_n[i, j] = sp
35563551

35573552
from_self_cache[I] = M_coeffs
3558-
i += 1
35593553

35603554
# Save the transition matrix
35613555
inverse_transition_matrices[n] = transition_matrix_n

src/sage/combinat/plane_partition.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__(self, parent, pp, check=True):
139139
self._max_y = 0
140140
self._max_z = 0
141141
else:
142-
(self._max_x, self._max_y, self._max_z) = self.parent()._box
142+
self._max_x, self._max_y, self._max_z = self.parent()._box
143143

144144
def __richcmp__(self, other, op):
145145
r"""
@@ -1098,17 +1098,14 @@ def to_order_ideal(self):
10981098
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0), (2, 0, 0)]
10991099
"""
11001100
from sage.combinat.posets.poset_examples import posets
1101-
(a, b, c) = (self._max_x, self._max_y, self._max_z)
1101+
a, b, c = (self._max_x, self._max_y, self._max_z)
11021102
Q = posets.ProductOfChains([a, b, c])
1103-
count = 0
11041103
generate = []
11051104
for i, row in enumerate(self):
11061105
for j, val in enumerate(row):
11071106
if val > 0:
1108-
generate.append((i, j, val-1))
1109-
count += 1
1110-
oi = Q.order_ideal(generate)
1111-
return oi
1107+
generate.append((i, j, val - 1))
1108+
return Q.order_ideal(generate)
11121109

11131110
def maximal_boxes(self) -> list:
11141111
r"""

src/sage/combinat/posets/poset_examples.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,10 +1273,8 @@ def TetrahedralPoset(n, *colors, **labels):
12731273
elem_labels = {}
12741274
if 'labels' in labels:
12751275
if labels['labels'] == 'integers':
1276-
labelcount = 0
1277-
for i, j, k in elem:
1278-
elem_labels[(i, j, k)] = labelcount
1279-
labelcount += 1
1276+
for labelcount, ijk in enumerate(elem):
1277+
elem_labels[ijk] = labelcount
12801278
for c in colors:
12811279
for i, j, k in elem:
12821280
if i + j + k < n - 1:

src/sage/combinat/sf/dual.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,14 @@ def _precompute(self, n):
394394

395395
# For every partition p of size n, compute self(p) in
396396
# terms of the dual basis using the scalar product.
397-
i = 0
398-
for s_part in partitions_n:
397+
for i, s_part in enumerate(partitions_n):
399398
# s_part corresponds to self(dual_basis(part))
400399
# s_mcs corresponds to self(dual_basis(part))._monomial_coefficients
401400
s_mcs = {}
402401

403402
# We need to compute the scalar product of d[s_part] and
404403
# all of the d[p_part]'s
405-
j = 0
406-
for p_part in partitions_n:
404+
for j, p_part in enumerate(partitions_n):
407405
# Compute the scalar product of d[s_part] and d[p_part]
408406
sp = zero
409407
for ds_part in d[s_part]:
@@ -413,10 +411,7 @@ def _precompute(self, n):
413411
s_mcs[p_part] = sp
414412
transition_matrix_n[i,j] = sp
415413

416-
j += 1
417-
418414
self._to_self_cache[ s_part ] = s_mcs
419-
i += 1
420415

421416
else:
422417
# Now the other case. Note that just being in this case doesn't

src/sage/combinat/words/paths.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,16 +1197,14 @@ def is_simple(self) -> bool:
11971197
sage: P('aabdee').is_simple()
11981198
False
11991199
"""
1200-
n = 0
12011200
s = set()
12021201
include_last = not self.is_closed()
1203-
for p in self.points(include_last=include_last):
1202+
for n, p in enumerate(self.points(include_last=include_last), start=1):
12041203
# We need the elements to have a common parent,
12051204
# so we convert the points to immutable vectors.
12061205
v = vector(p)
12071206
v.set_immutable()
12081207
s.add(v)
1209-
n += 1
12101208
if len(s) != n:
12111209
return False
12121210
return True

0 commit comments

Comments
 (0)