diff --git a/src/sage/combinat/cluster_algebra_quiver/mutation_type.py b/src/sage/combinat/cluster_algebra_quiver/mutation_type.py index 6ff5777a0a6..3e27b9efe32 100644 --- a/src/sage/combinat/cluster_algebra_quiver/mutation_type.py +++ b/src/sage/combinat/cluster_algebra_quiver/mutation_type.py @@ -20,7 +20,7 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -import os +from pathlib import Path import pickle from copy import copy @@ -1276,16 +1276,16 @@ def load_data(n, user=True): # we check # - if the data is stored by the user, and if this is not the case # - if the data is stored by the optional package install - paths = [SAGE_SHARE] + paths = [Path(SAGE_SHARE)] if user: - paths.append(DOT_SAGE) + paths.append(Path(DOT_SAGE)) data = {} for path in paths: - filename = os.path.join(path, 'cluster_algebra_quiver', 'mutation_classes_%s.dig6'%n) + file = path / 'cluster_algebra_quiver' / f'mutation_classes_{n}.dig6' try: - with open(filename, 'rb') as fobj: + with open(file, 'rb') as fobj: data_new = pickle.load(fobj) - except Exception: + except (OSError, FileNotFoundError, pickle.UnpicklingError): # File does not exist, corrupt pickle, wrong Python version... pass else: diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py index 4969d141b65..087abdbc7fe 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py @@ -16,7 +16,7 @@ # https://www.gnu.org/licenses/ # *************************************************************************** from __future__ import annotations -import os +from pathlib import Path import pickle from sage.structure.sage_object import SageObject @@ -2272,9 +2272,9 @@ def _save_data_dig6(n, types='ClassicalExceptional', verbose=False): data.update(_construct_exceptional_mutation_classes(n)) from sage.env import DOT_SAGE - types_path = os.path.join(DOT_SAGE, 'cluster_algebra_quiver') - types_file = os.path.join(types_path, 'mutation_classes_%s.dig6' % n) - os.makedirs(types_path, exist_ok=True) + types_path = Path(DOT_SAGE) / 'cluster_algebra_quiver' + types_path.mkdir(exist_ok=True) + types_file = types_path / f'mutation_classes_{n}.dig6' from sage.misc.temporary_file import atomic_write with atomic_write(types_file, binary=True) as f: pickle.dump(data, f) diff --git a/src/sage/groups/perm_gps/permgroup_named.py b/src/sage/groups/perm_gps/permgroup_named.py index 51b5f96521c..b50b9581f00 100644 --- a/src/sage/groups/perm_gps/permgroup_named.py +++ b/src/sage/groups/perm_gps/permgroup_named.py @@ -77,18 +77,16 @@ permutation groups - the construction is too slow - unless (for small values or the parameter) they are made using explicit generators. """ - -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2006 William Stein # David Joyner # # Distributed under the terms of the GNU General Public License (GPL) -# http://www.gnu.org/licenses/ -#***************************************************************************** - -import os +# https://www.gnu.org/licenses/ +# **************************************************************************** +from pathlib import Path -from sage.rings.all import Integer +from sage.rings.all import Integer from sage.libs.gap.libgap import libgap from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF from sage.arith.all import factor, valuation @@ -259,9 +257,9 @@ def __init__(self, domain=None): from sage.categories.finite_permutation_groups import FinitePermutationGroups from sage.categories.category import Category - #Note that we skip the call to the superclass initializer in order to - #avoid infinite recursion since SymmetricGroup is called by - #PermutationGroupElement + # Note that we skip the call to the superclass initializer in order to + # avoid infinite recursion since SymmetricGroup is called by + # PermutationGroupElement cat = Category.join([FinitePermutationGroups(), FiniteWeylGroups().Irreducible()]) super(PermutationGroup_generic, self).__init__(category=cat) @@ -270,7 +268,7 @@ def __init__(self, domain=None): self._domain_to_gap = {key: i+1 for i, key in enumerate(self._domain)} self._domain_from_gap = {i+1: key for i, key in enumerate(self._domain)} - #Create the generators for the symmetric group + # Create the generators for the symmetric group gens = [tuple(self._domain)] if len(self._domain) > 2: gens.append(tuple(self._domain[:2])) @@ -348,7 +346,7 @@ def cartan_type(self): ['A', 0] """ from sage.combinat.root_system.cartan_type import CartanType - return CartanType(['A', max(self.degree() - 1,0)]) + return CartanType(['A', max(self.degree() - 1, 0)]) def coxeter_matrix(self): r""" @@ -493,8 +491,8 @@ def conjugacy_classes_representatives(self): from sage.combinat.partition import Partitions_n from sage.groups.perm_gps.symgp_conjugacy_class import default_representative n = len(self.domain()) - return [ default_representative(la, self) - for la in reversed(Partitions_n(n)) ] + return [default_representative(la, self) + for la in reversed(Partitions_n(n))] def conjugacy_classes_iterator(self): """ @@ -922,12 +920,12 @@ def __init__(self, n): a = [tuple(range(1, halfr+1)), tuple(range(halfr+1, r+1))] # With an odd part, a cycle of length m will give the right order for a if m > 1: - a.append( tuple(range(r+1, r+m+1)) ) + a.append(tuple(range(r + 1, r + m + 1))) # Representation of x # Four-cycles that will conjugate the generator a properly - x = [(i+1, (-i)%halfr + halfr + 1, (fourthr+i)%halfr + 1, (-fourthr-i)%halfr + halfr + 1) - for i in range(0, fourthr)] + x = [(i+1, (-i) % halfr + halfr + 1, (fourthr+i) % halfr + 1, (-fourthr-i)%halfr + halfr + 1) + for i in range(0, fourthr)] # With an odd part, transpositions will conjugate the m-cycle to create inverse if m > 1: x += [(r+i+1, r+m-i) for i in range(0, (m-1)//2)] @@ -1000,7 +998,7 @@ def __init__(self): AUTHOR: -- Bobby Moretti (2006-10) """ - gens = [(1,2),(3,4)] + gens = [(1, 2), (3, 4)] PermutationGroup_generic.__init__(self, gens) def _repr_(self): @@ -1047,7 +1045,8 @@ def _repr_(self): sage: G = groups.permutation.Janko(1); G # optional - gap_packages internet Janko group J1 of order 175560 as a permutation group """ - return "Janko group J%s of order %s as a permutation group"%(self._n,self.order()) + return "Janko group J%s of order %s as a permutation group" % (self._n, self.order()) + class SuzukiSporadicGroup(PermutationGroup_unique): def __init__(self): @@ -1301,8 +1300,6 @@ def __init__(self, factors): 250 sage: TestSuite(G).run() # long time """ - - if not isinstance(factors, list): msg = "factors of abelian group must be a list, not {}" raise TypeError(msg.format(factors)) @@ -1433,9 +1430,9 @@ def __init__(self, n): if n == 1: gens = CyclicPermutationGroup(2).gens() elif n == 2: - gens = ((1,2),(3,4)) + gens = ((1, 2), (3, 4)) else: - gen1 = tuple((i, n-i+1) for i in range(1, n//2 +1)) + gen1 = tuple((i, n - i + 1) for i in range(1, n // 2 + 1)) gens = tuple([tuple(gen0), gen1]) PermutationGroup_generic.__init__(self, gens) @@ -1447,8 +1444,7 @@ def _repr_(self): sage: G = DihedralGroup(5); G Dihedral group of order 10 as a permutation group """ - return "Dihedral group of order %s as a permutation group"%self.order() - + return f"Dihedral group of order {self.order()} as a permutation group" class SplitMetacyclicGroup(PermutationGroup_unique): @@ -1578,12 +1574,12 @@ def __init__(self, p, m): y = [1] point = 1 for i in range(p**(m-1)-1): - next = (point + 1 + p**(m-2))%(p**(m-1)) + next = (point + 1 + p**(m-2)) % (p**(m-1)) if next == 0: next = p**(m-1) y.append(next) point = next - PermutationGroup_unique.__init__(self, gens = [x,y]) + PermutationGroup_unique.__init__(self, gens=[x, y]) def _repr_(self): """ @@ -1594,8 +1590,9 @@ def _repr_(self): """ return 'The split metacyclic group of order %s ^ %s' % (self.p, self.m) + class SemidihedralGroup(PermutationGroup_unique): - def __init__(self,m): + def __init__(self, m): r""" The semidihedral group of order `2^m`. @@ -1687,12 +1684,12 @@ def __init__(self,m): y = [1] k = 1 for i in range(2**(m-1)-1): - next = (k - 1 + 2**(m-2))%(2**(m-1)) + next = (k - 1 + 2**(m-2)) % (2**(m-1)) if next == 0: next = 2**(m-1) y.append(next) k = next - PermutationGroup_unique.__init__(self, gens = [x,y]) + PermutationGroup_unique.__init__(self, gens=[x, y]) def _repr_(self): r""" @@ -1753,7 +1750,8 @@ def _repr_(self): sage: G = MathieuGroup(12); G Mathieu group of degree 12 and order 95040 as a permutation group """ - return "Mathieu group of degree %s and order %s as a permutation group"%(self._n,self.order()) + return "Mathieu group of degree %s and order %s as a permutation group"%(self._n, self.order()) + class TransitiveGroup(PermutationGroup_unique): def __init__(self, d, n): @@ -1832,7 +1830,6 @@ def __init__(self, d, n): gap_group = libgap.TransitiveGroup(d, n) PermutationGroup_generic.__init__(self, gap_group=gap_group) - def transitive_number(self): """ Return the index of this group in the GAP database, starting at 1 @@ -1960,7 +1957,8 @@ def __contains__(self, G): sage: 1 in TransitiveGroups() False """ - return isinstance(G,TransitiveGroup) + return isinstance(G, TransitiveGroup) + class TransitiveGroupsOfDegree(CachedRepresentation, Parent): r""" @@ -2380,7 +2378,8 @@ def __contains__(self, G): sage: 1 in PrimitiveGroups() False """ - return isinstance(G,PrimitiveGroup) + return isinstance(G, PrimitiveGroup) + class PrimitiveGroupsOfDegree(CachedRepresentation, Parent): """ @@ -2418,7 +2417,7 @@ def __init__(self, n): Category of finite enumerated sets """ self._degree = n - Parent.__init__(self, category = FiniteEnumeratedSets()) + Parent.__init__(self, category=FiniteEnumeratedSets()) def _repr_(self): """ @@ -2756,8 +2755,8 @@ def ramification_module_decomposition_hurwitz_curve(self): F = self.base_ring() q = F.order() - libgap.Read(os.path.join(SAGE_EXTCODE, 'gap', 'joyner', - 'hurwitz_crv_rr_sp.gap')) + libgap.Read(Path(SAGE_EXTCODE) / 'gap' / 'joyner' / + 'hurwitz_crv_rr_sp.gap') mults = libgap.eval("ram_module_hurwitz({q})".format(q=q)) return mults.sage() @@ -2800,11 +2799,12 @@ def ramification_module_decomposition_modular_curve(self): raise ValueError("degree must be 2") F = self.base_ring() q = F.order() - libgap.Read(os.path.join(SAGE_EXTCODE, 'gap', 'joyner', - 'modular_crv_rr_sp.gap')) + libgap.Read(Path(SAGE_EXTCODE) / 'gap' / 'joyner' / + 'modular_crv_rr_sp.gap') mults = libgap.eval("ram_module_X({q})".format(q=q)) return mults.sage() + class PSp(PermutationGroup_plg): def __init__(self, n, q, name='a'): """ @@ -2868,8 +2868,10 @@ def __str__(self): """ return "The projective symplectic linear group of degree %s over %s"%(self._n, self.base_ring()) + PSP = PSp + class PermutationGroup_pug(PermutationGroup_plg): def field_of_definition(self): """ @@ -2929,7 +2931,8 @@ def _repr_(self): The projective special unitary group of degree 2 over Finite Field of size 3 """ - return "The projective special unitary group of degree %s over %s"%(self._n, self.base_ring()) + return "The projective special unitary group of degree %s over %s" % (self._n, self.base_ring()) + class PGU(PermutationGroup_pug): def __init__(self, n, q, name='a'):