From 0bfd7e256d965820139d80b863a75d34fd5bd0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 4 Sep 2025 08:36:51 +0200 Subject: [PATCH 1/2] various ruff SIM fixes --- surface_dynamics/flat_surfaces/abelian_strata.py | 4 +--- .../flat_surfaces/masur_veech_volumes.py | 4 +--- .../flat_surfaces/origamis/origami_database.py | 2 +- .../flat_surfaces/single_cylinder.py | 2 +- surface_dynamics/flat_surfaces/strata.py | 16 +++------------- surface_dynamics/flat_surfaces/tests.py | 3 ++- surface_dynamics/misc/constellation.py | 2 +- surface_dynamics/misc/factored_denominator.py | 2 +- surface_dynamics/misc/permutation.py | 6 ++---- 9 files changed, 13 insertions(+), 28 deletions(-) diff --git a/surface_dynamics/flat_surfaces/abelian_strata.py b/surface_dynamics/flat_surfaces/abelian_strata.py index c926c49f..6b752192 100644 --- a/surface_dynamics/flat_surfaces/abelian_strata.py +++ b/surface_dynamics/flat_surfaces/abelian_strata.py @@ -201,9 +201,7 @@ def _cylinder_diagrams_with_symmetric(iterator): yield cd.inverse() elif sym == (True, False, False): yield cd.vertical_symmetry() - elif sym == (False, True, False): - yield cd.horizontal_symmetry() - elif sym == (False, False, True): + elif sym == (False, True, False) or sym == (False, False, True): yield cd.horizontal_symmetry() else: raise RuntimeError diff --git a/surface_dynamics/flat_surfaces/masur_veech_volumes.py b/surface_dynamics/flat_surfaces/masur_veech_volumes.py index 19c8241b..848cf20d 100644 --- a/surface_dynamics/flat_surfaces/masur_veech_volumes.py +++ b/surface_dynamics/flat_surfaces/masur_veech_volumes.py @@ -137,9 +137,7 @@ def masur_veech_volume(C, rational=False, method=None): elif isinstance(C, AbelianStratum): vol = sum(abelian_volumes_table[CC] for CC in C.components()) S = C - elif isinstance(C, QuadraticStratumComponent): - raise NotImplementedError('quadratic differentials') - elif isinstance(C, QuadraticStratum): + elif isinstance(C, (QuadraticStratumComponent, QuadraticStratum)): raise NotImplementedError('quadratic differentials') else: raise ValueError('invalid input') diff --git a/surface_dynamics/flat_surfaces/origamis/origami_database.py b/surface_dynamics/flat_surfaces/origamis/origami_database.py index ee196ad9..a4343afd 100644 --- a/surface_dynamics/flat_surfaces/origamis/origami_database.py +++ b/surface_dynamics/flat_surfaces/origamis/origami_database.py @@ -1594,7 +1594,7 @@ def build(self, comp, N, force_computation=False, verbose=False): if key in self._data_to_entry: data[key] = self._entry_to_data[key](data[key]) - value = [data.get(e,None) for e in columns] + value = [data.get(e) for e in columns] self.add_row('origamis', value, columns) if verbose: diff --git a/surface_dynamics/flat_surfaces/single_cylinder.py b/surface_dynamics/flat_surfaces/single_cylinder.py index 97c7bd5a..622a0e77 100644 --- a/surface_dynamics/flat_surfaces/single_cylinder.py +++ b/surface_dynamics/flat_surfaces/single_cylinder.py @@ -1755,7 +1755,7 @@ def cylinder_concatenation(perm_1, perm_2, alphabet=None): if bot_row1[i] == 1: bot_row1[i] += length_1 for j in range(length_2): - if not bot_row2[j] == 1: + if bot_row2[j] != 1: bot_row2[j] += length_1 bot_row = bot_row1 + bot_row2 + [0] perm = GeneralizedPermutation(top_row,bot_row) diff --git a/surface_dynamics/flat_surfaces/strata.py b/surface_dynamics/flat_surfaces/strata.py index f73c72f0..18bfea02 100644 --- a/surface_dynamics/flat_surfaces/strata.py +++ b/surface_dynamics/flat_surfaces/strata.py @@ -402,9 +402,7 @@ def connected_components(self): s = sum(zeros) genus = s // 2 + 1 - if genus == 1: - return (HypASC(self),) - elif genus == 2: + if genus == 1 or genus == 2: return (HypASC(self),) elif genus == 3: if zeros == (2, 2) or zeros == (4,): @@ -450,9 +448,7 @@ def connected_components(self): if zeros == (4,) or zeros == (3, 1): # empty! return () - elif zeros == (6, -1, -1): - return (HQSC(self), GTNQSC(self)) - elif zeros == (3, 3, -1, -1): + elif zeros == (6, -1, -1) or zeros == (3, 3, -1, -1): return (HQSC(self), GTNQSC(self)) elif zeros == (2, 2) or zeros == (2, 1, 1) or zeros == (1, 1, 1, 1): return (GTHQSC(self),) @@ -468,13 +464,7 @@ def connected_components(self): elif zeros == (6, 6) or zeros == (6, 3, 3) or zeros == (3, 3, 3, 3): return (HQSC(self), REQSC(self), IEQSC(self)) else: - if len(zeros) == 2 and zeros[0] % 4 == 2 and zeros[1] % 4 == 2: - return (HQSC(self), NQSC(self)) - elif len(zeros) == 4 and zeros[0] == zeros[1] and zeros[2] == zeros[3] and zeros[0] % 2 and zeros[2] % 2: - return (HQSC(self), NQSC(self)) - elif len(zeros) == 3 and zeros[0] == zeros[1] and zeros[0] % 2 and zeros[2] % 4 == 2: - return (HQSC(self), NQSC(self)) - elif len(zeros) == 3 and zeros[1] == zeros[2] and zeros[1] % 2 and zeros[0] % 4 == 2: + if len(zeros) == 2 and zeros[0] % 4 == 2 and zeros[1] % 4 == 2 or len(zeros) == 4 and zeros[0] == zeros[1] and zeros[2] == zeros[3] and zeros[0] % 2 and zeros[2] % 2 or (len(zeros) == 3 and zeros[0] == zeros[1] and zeros[0] % 2 and zeros[2] % 4 == 2 or len(zeros) == 3 and zeros[1] == zeros[2] and zeros[1] % 2 and zeros[0] % 4 == 2): return (HQSC(self), NQSC(self)) else: return (CQSC(self),) diff --git a/surface_dynamics/flat_surfaces/tests.py b/surface_dynamics/flat_surfaces/tests.py index 77f17a33..254b653f 100644 --- a/surface_dynamics/flat_surfaces/tests.py +++ b/surface_dynamics/flat_surfaces/tests.py @@ -132,7 +132,8 @@ def test_random(self): sage: Test().test_random() #random Doing random test """ - tests = [a for a in Test.__dict__.keys() if a[:5] == "test_" and a != "test_random"] + tests = [a for a in Test.__dict__ + if a[:5] == "test_" and a != "test_random"] name = prandom.choice(tests) print("Doing random test %s" % name) Test.__dict__[name](self) diff --git a/surface_dynamics/misc/constellation.py b/surface_dynamics/misc/constellation.py index a756011c..41a8e9e7 100644 --- a/surface_dynamics/misc/constellation.py +++ b/surface_dynamics/misc/constellation.py @@ -1325,7 +1325,7 @@ def random_element(self, mutable=False): g = [SymmetricGroup(d).random_element() for _ in range(l-1)] G = PermutationGroup(g) - while not G.degree() == d or (self._connected and not G.is_transitive()): + while G.degree() != d or (self._connected and not G.is_transitive()): g = [SymmetricGroup(d).random_element() for _ in range(l-1)] G = PermutationGroup(g) diff --git a/surface_dynamics/misc/factored_denominator.py b/surface_dynamics/misc/factored_denominator.py index ad63440e..a2c82c3f 100644 --- a/surface_dynamics/misc/factored_denominator.py +++ b/surface_dynamics/misc/factored_denominator.py @@ -122,7 +122,7 @@ def vector_to_linear_form_string(u, var_names): s += ' + %d*%s' % (j, var) first = False - return '0' if not s else s + return s if s else '0' # NOTE: should this be an instance of Factorization? diff --git a/surface_dynamics/misc/permutation.py b/surface_dynamics/misc/permutation.py index 53956bad..c782a3cd 100644 --- a/surface_dynamics/misc/permutation.py +++ b/surface_dynamics/misc/permutation.py @@ -242,10 +242,8 @@ def perm_is_one(l, n=None): """ if n is None: n = len(l) - for i in range(n): - if l[i] != -1 and l[i] != i: - return False - return True + return all(not (l[i] != -1 and l[i] != i) for i in range(n)) + def perm_is_regular(p, k=None, n=None): r""" From 5f4660125c384220cdb4909356c38803022955ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 6 Sep 2025 08:19:24 +0200 Subject: [PATCH 2/2] minor detail --- surface_dynamics/misc/permutation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/surface_dynamics/misc/permutation.py b/surface_dynamics/misc/permutation.py index c782a3cd..d86ae407 100644 --- a/surface_dynamics/misc/permutation.py +++ b/surface_dynamics/misc/permutation.py @@ -216,7 +216,7 @@ def perm_check(l, n=None): return ra_seen == im_seen -def perm_is_one(l, n=None): +def perm_is_one(l, n=None) -> bool: r""" Test whether ``l`` is the identity on its domain. @@ -242,10 +242,10 @@ def perm_is_one(l, n=None): """ if n is None: n = len(l) - return all(not (l[i] != -1 and l[i] != i) for i in range(n)) + return all(l[i] == -1 or l[i] == i for i in range(n)) -def perm_is_regular(p, k=None, n=None): +def perm_is_regular(p, k=None, n=None) -> bool: r""" Return whether the cycle decomposition of ``p`` is only made of cycles of identical lengths.