From 0a94fbba21f5b0f1950413439b6ae5b8e622ac7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= <chapoton@unistra.fr>
Date: Mon, 27 Jan 2025 10:32:56 +0100
Subject: [PATCH] fixing PLW0120

---
 src/sage/combinat/diagram_algebras.py            | 3 +--
 src/sage/combinat/regular_sequence.py            | 3 +--
 src/sage/combinat/words/finite_word.py           | 9 +++------
 src/sage/combinat/words/morphic.py               | 5 ++---
 src/sage/combinat/words/morphism.py              | 3 +--
 src/sage/combinat/words/word_generators.py       | 9 +++------
 src/sage/modular/modform/element.py              | 5 ++---
 src/sage/rings/polynomial/binary_form_reduce.py  | 7 +++----
 src/sage/schemes/elliptic_curves/hom.py          | 3 +--
 src/sage/schemes/elliptic_curves/hom_velusqrt.py | 3 +--
 10 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py
index 841c9efe9d3..758a1f1432d 100644
--- a/src/sage/combinat/diagram_algebras.py
+++ b/src/sage/combinat/diagram_algebras.py
@@ -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 = []
diff --git a/src/sage/combinat/regular_sequence.py b/src/sage/combinat/regular_sequence.py
index 6ad1c12c088..5ce785d6a42 100644
--- a/src/sage/combinat/regular_sequence.py
+++ b/src/sage/combinat/regular_sequence.py
@@ -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"""
diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py
index ba9bf3f2157..a47c8006767 100644
--- a/src/sage/combinat/words/finite_word.py
+++ b/src/sage/combinat/words/finite_word.py
@@ -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"""
@@ -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
 
@@ -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"""
diff --git a/src/sage/combinat/words/morphic.py b/src/sage/combinat/words/morphic.py
index 160f4e2243a..1d79d9dd1fc 100644
--- a/src/sage/combinat/words/morphic.py
+++ b/src/sage/combinat/words/morphic.py
@@ -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
diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py
index 343fe8af9eb..3939e450b99 100644
--- a/src/sage/combinat/words/morphism.py
+++ b/src/sage/combinat/words/morphism.py
@@ -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"""
diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py
index 05ccb242508..a0150f8ed31 100644
--- a/src/sage/combinat/words/word_generators.py
+++ b/src/sage/combinat/words/word_generators.py
@@ -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"""
@@ -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
 
@@ -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"""
diff --git a/src/sage/modular/modform/element.py b/src/sage/modular/modform/element.py
index 3fdabbfed7b..7b8a7e0e13f 100644
--- a/src/sage/modular/modform/element.py
+++ b/src/sage/modular/modform/element.py
@@ -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()
diff --git a/src/sage/rings/polynomial/binary_form_reduce.py b/src/sage/rings/polynomial/binary_form_reduce.py
index 8d4c770072d..f56dfe459ac 100644
--- a/src/sage/rings/polynomial/binary_form_reduce.py
+++ b/src/sage/rings/polynomial/binary_form_reduce.py
@@ -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()
diff --git a/src/sage/schemes/elliptic_curves/hom.py b/src/sage/schemes/elliptic_curves/hom.py
index 96700fa254d..aef794ed8f9 100644
--- a/src/sage/schemes/elliptic_curves/hom.py
+++ b/src/sage/schemes/elliptic_curves/hom.py
@@ -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')
diff --git a/src/sage/schemes/elliptic_curves/hom_velusqrt.py b/src/sage/schemes/elliptic_curves/hom_velusqrt.py
index d8cf1971f45..31968d8578f 100644
--- a/src/sage/schemes/elliptic_curves/hom_velusqrt.py
+++ b/src/sage/schemes/elliptic_curves/hom_velusqrt.py
@@ -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):