Skip to content

Commit

Permalink
sagemathgh-39384: fixing PLW0120
Browse files Browse the repository at this point in the history
this is about wrong use of `else` in `for` loops without `break`

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.

URL: sagemath#39384
Reported by: Frédéric Chapoton
Reviewer(s): Vincent Macri
  • Loading branch information
Release Manager committed Jan 28, 2025
2 parents d64128d + 0a94fbb commit 3c260c3
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=86711d4cbef2cd4e7bb4afcde36965e5dea908e0
sha256=9793cf92ebdceb09050a585294de93c242c033745a0012cae1bd301d307a45df
sha1=387f1f8a4e140c698a75c7c53756963ab76e00a6
sha256=e932cd379d5d2d6629d02166db86f31d6737ff0ceaaf434c630b1984156b9124
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
efc0914cd8d72a9bdfdcca4511b55e290b9b6674
bebda5eff2b63b6014245209827b13bf7a323631
3 changes: 1 addition & 2 deletions src/sage/combinat/diagram_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -4802,8 +4802,7 @@ def insert_pairing(cur, intervals):
else:
level.append(cur)
return # We have stopped
else:
intervals.append([cur])
intervals.append([cur])
# Build a set of intervals that defines where to draw the diagram
intervals = [[]]
propogating = []
Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/regular_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,8 +1882,7 @@ def some_inverse_U_matrix(lines):
return U.inverse(), m_indices
except ZeroDivisionError:
pass
else:
raise RuntimeError('no invertible submatrix found')
raise RuntimeError('no invertible submatrix found')

def linear_combination_candidate(t_L, r_L, lines):
r"""
Expand Down
9 changes: 3 additions & 6 deletions src/sage/combinat/words/finite_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -2367,8 +2367,7 @@ def longest_common_suffix(self, other):
for i, (b, c) in iter:
if b != c:
return self[-i:]
else:
return self[-i-1:]
return self[-i-1:]

def is_palindrome(self, f=None):
r"""
Expand Down Expand Up @@ -3739,8 +3738,7 @@ def is_subword_of(self, other):
for e in other:
if s == e:
s = next(its)
else:
return False
return False
except StopIteration:
return True

Expand Down Expand Up @@ -3881,8 +3879,7 @@ def is_lyndon(self) -> bool:
else:
# we found the first word in the lyndon factorization;
return False
else:
return i == 0
return i == 0

def lyndon_factorization(self):
r"""
Expand Down
5 changes: 2 additions & 3 deletions src/sage/combinat/words/morphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ def __iter__(self):
try:
for a in self._morphism.image(next(w)):
yield self._coding[a]
else:
next_w = next(w)
w = chain([next_w], w, self._morphism.image(next_w))
next_w = next(w)
w = chain([next_w], w, self._morphism.image(next_w))
except StopIteration:
return
3 changes: 1 addition & 2 deletions src/sage/combinat/words/morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,7 @@ def _check_primitive(self):
for image in self.images():
if not dom_alphabet <= set(image):
return False
else:
return True
return True

def is_primitive(self):
r"""
Expand Down
9 changes: 3 additions & 6 deletions src/sage/combinat/words/word_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,7 @@ def _FibonacciWord_RecursiveConstructionIterator(self, alphabet=(0, 1)):
for i in it:
n += 1
yield alphabet[i]
else:
Fib1, Fib0 = Fib1 + Fib0, Fib1
Fib1, Fib0 = Fib1 + Fib0, Fib1

def FixedPointOfMorphism(self, morphism, first_letter):
r"""
Expand Down Expand Up @@ -962,8 +961,7 @@ def _CharacteristicSturmianWord_LetterIterator(self, cf, alphabet=(0, 1)):
for i in s1[n:]:
n += 1
yield alphabet[i]
else:
s1, s0 = s1*next(cf) + s0, s1
s1, s0 = s1*next(cf) + s0, s1
except StopIteration:
return

Expand Down Expand Up @@ -1306,8 +1304,7 @@ def _StandardEpisturmianWord_LetterIterator(self, directive_word):
for x in w[n:]:
n += 1
yield x
else:
w = W(w * W(next(d))).palindromic_closure()
w = W(w * W(next(d))).palindromic_closure()

def MinimalSmoothPrefix(self, n):
r"""
Expand Down
5 changes: 2 additions & 3 deletions src/sage/modular/modform/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2502,9 +2502,8 @@ def minimal_twist(self, p=None):
h, tau = g.minimal_twist(p=None)
M = chi.modulus().lcm(tau.modulus())
return (h, chi.extend(M)*tau.extend(M))
else:
# f locally minimal at all p, hence globally minimal
return (self, DirichletGroup(1, self.base_ring())(1))
# f locally minimal at all p, hence globally minimal
return (self, DirichletGroup(1, self.base_ring())(1))

p = ZZ(p)
N = self.level()
Expand Down
7 changes: 3 additions & 4 deletions src/sage/rings/polynomial/binary_form_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@ def covariant_z0(F, z0_cov=False, prec=53, emb=None, error_limit=0.000001):
z = v0[1].constant_coefficient() + v0[0].constant_coefficient()*CF.gen(0)
err = z.diameter() # precision
zz = (w - z).abs().lower() # difference in w and z
else:
# despite there is no break, this happens
if err > error_limit or err.is_NaN():
raise ValueError("accuracy of Newton's root not within tolerance(%s > %s), increase precision" % (err, error_limit))
# despite there is no break, this happens
if err > error_limit or err.is_NaN():
raise ValueError("accuracy of Newton's root not within tolerance(%s > %s), increase precision" % (err, error_limit))
if z.imag().upper() <= z.diameter():
raise ArithmeticError("Newton's method converged to z not in the upper half plane")
z = z.center()
Expand Down
3 changes: 1 addition & 2 deletions src/sage/schemes/elliptic_curves/hom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,7 @@ def compare_via_evaluation(left, right):
if P._has_order_at_least(4*d + 1, attempts=50):
# if P.height(precision=250) == 0: # slow sometimes
return left._eval(P) == right._eval(P)
else:
assert False, "couldn't find a point of large enough order"
assert False, "couldn't find a point of large enough order"

else:
raise NotImplementedError('not implemented for this base field')
Expand Down
3 changes: 1 addition & 2 deletions src/sage/schemes/elliptic_curves/hom_velusqrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ def _point_outside_subgroup(P):
Q = E.random_point()
if n*Q or not P.weil_pairing(Q,n).is_one():
return Q
else:
raise NotImplementedError('could not find a point outside the kernel')
raise NotImplementedError('could not find a point outside the kernel')


class EllipticCurveHom_velusqrt(EllipticCurveHom):
Expand Down

0 comments on commit 3c260c3

Please sign in to comment.