Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #34144: modernize super in combinat (step one)
Browse files Browse the repository at this point in the history
using the short syntax `super()`

URL: https://trac.sagemath.org/34144
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Jul 18, 2022
2 parents d22a144 + 87140db commit e3ababd
Show file tree
Hide file tree
Showing 54 changed files with 115 additions and 119 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=b5a2cfbb85e9d1afd3c151429525944f1e0ca84f
md5=8cf9a8e717fe11a7c6fb7aa41975a7a1
cksum=2226307451
sha1=7f35111c9a2aeb985580f13c2f1f72b2219ffcb1
md5=30cf7cce73540a45384762cea5da5f62
cksum=2110985588
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
413ff13c54c4738b14d64eb7e7e6b2d06439d12c
b393ee3e8e5501fd7e9101d884c743567df1816d
7 changes: 3 additions & 4 deletions src/sage/combinat/abstract_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2085,15 +2085,15 @@ def __init__(self, parent, children, label=None, check=True):
"""
# We must initialize the label before the subtrees to allows rooted
# trees canonization. Indeed it needs that ``self``._hash_() is working
# at the end of the call super(..., self).__init__(...)
# at the end of the call super().__init__(...)
if isinstance(children, AbstractLabelledTree):
if label is None:
self._label = children._label
else:
self._label = label
else:
self._label = label
super(AbstractLabelledTree, self).__init__(parent, children, check=check)
super().__init__(parent, children, check=check)

def _repr_(self):
"""
Expand Down Expand Up @@ -2211,8 +2211,7 @@ def __eq__(self, other):
sage: t1 == t2
False
"""
return (super(AbstractLabelledTree, self).__eq__(other) and
self._label == other._label)
return super().__eq__(other) and self._label == other._label

def _hash_(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/baxter_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, n):
self.element_class = Permutations(n).element_class
self._n = ZZ(n)
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
super(BaxterPermutations_size, self).__init__(category=FiniteEnumeratedSets())
super().__init__(category=FiniteEnumeratedSets())

def _repr_(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/blob_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def __classcall_private__(cls, k, q1, q2, q3, base_ring=None, prefix='B'):
q1 = base_ring(q1)
q2 = base_ring(q2)
q3 = base_ring(q3)
return super(BlobAlgebra, cls).__classcall__(cls, k, q1, q2, q3, base_ring, prefix)
return super().__classcall__(cls, k, q1, q2, q3, base_ring, prefix)

def __init__(self, k, q1, q2, q3, base_ring, prefix):
r"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/combinat/chas/fsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def coerce_base_ring(self, x):
# Otherwise lift that basis up and then coerce over
target = getattr(FSym, R._realization_name())()
return self._coerce_map_via([target], R)
return super(FSymBasis_abstract, self)._coerce_map_from_(R)
return super()._coerce_map_from_(R)

def some_elements(self):
r"""
Expand Down Expand Up @@ -633,7 +633,7 @@ def R_to_G_on_basis(alpha):
if descent_composition(t) == alpha)
return ribbon.module_morphism(R_to_G_on_basis, codomain=self)
return self._coerce_map_via([ribbon], R)
return super(FreeSymmetricFunctions.Fundamental, self)._coerce_map_from_(R)
return super()._coerce_map_from_(R)

def dual_basis(self):
r"""
Expand Down Expand Up @@ -963,7 +963,7 @@ def s_to_F_on_basis(mu):
return self.sum_of_monomials(StandardTableaux(mu))
return s.module_morphism(s_to_F_on_basis, codomain=self)
return self._coerce_map_via([s], R)
return super(FreeSymmetricFunctions_Dual.FundamentalDual, self)._coerce_map_from_(R)
return super()._coerce_map_from_(R)

def dual_basis(self):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/chas/wqsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def coerce_base_ring(self, x):
# Otherwise lift that basis up and then coerce over
target = getattr(self.realization_of(), R._basis_name)()
return self._coerce_map_via([target], R)
return super(WQSymBasis_abstract, self)._coerce_map_from_(R)
return super()._coerce_map_from_(R)

@cached_method
def an_element(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/colored_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,13 @@ def _coerce_map_from_(self, C):
False
"""
if isinstance(C, Permutations) and C.n == self._n:
return lambda P, x: P.element_class(P, [P._C.zero()]*P._n, x)
return lambda P, x: P.element_class(P, [P._C.zero()] * P._n, x)
if self._m == 2 and isinstance(C, SignedPermutations) and C._n == self._n:
return lambda P, x: P.element_class(P,
[P._C.zero() if v == 1 else P._C.one()
for v in x._colors],
x._perm)
return super(ColoredPermutations, self)._coerce_map_from_(C)
return super()._coerce_map_from_(C)

def __iter__(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/combinat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ def __init__(self, parent, *args, **kwds):
L, = kwds.values()
else:
raise TypeError("__init__() takes exactly 2 arguments ({} given)".format(1 + len(args) + len(kwds)))
super(CombinatorialElement, self).__init__(L)
super().__init__(L)
super(CombinatorialObject, self).__init__(parent)


Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@ def __classcall_private__(cls, n):
sage: C is C3
True
"""
return super(Compositions_n, cls).__classcall__(cls, Integer(n))
return super().__classcall__(cls, Integer(n))

def __init__(self, n):
"""
Expand Down
14 changes: 7 additions & 7 deletions src/sage/combinat/composition_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def __init__(self, **kwds):
kwds.pop('max_entry')
else:
self.max_entry = None
super(CompositionTableaux, self).__init__(**kwds)
super().__init__(**kwds)

Element = CompositionTableau

Expand Down Expand Up @@ -588,11 +588,11 @@ def __init__(self, n, max_entry=None):
"""
if max_entry is None:
max_entry = n
super(CompositionTableaux_size, self).__init__(max_entry=max_entry,
category=FiniteEnumeratedSets())
super().__init__(max_entry=max_entry,
category=FiniteEnumeratedSets())
self.size = n

def __contains__(self,x):
def __contains__(self, x):
r"""
TESTS::
Expand Down Expand Up @@ -677,7 +677,7 @@ class CompositionTableaux_shape(CompositionTableaux):
"""
def __init__(self, comp, max_entry=None):
"""
Initialize ``sefl``.
Initialize ``self``.
TESTS::
Expand All @@ -689,8 +689,8 @@ def __init__(self, comp, max_entry=None):
"""
if max_entry is None:
max_entry = sum(comp)
super(CompositionTableaux_shape, self).__init__(max_entry = max_entry,
category = FiniteEnumeratedSets())
super().__init__(max_entry=max_entry,
category=FiniteEnumeratedSets())
self.shape = comp

def __iter__(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/derangements.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def __classcall_private__(cls, x):
True
"""
if x in ZZ:
x = list(range(1, x + 1))
return super(Derangements, cls).__classcall__(cls, tuple(x))
x = tuple(range(1, x + 1))
return super().__classcall__(cls, tuple(x))

def __init__(self, x):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/sage/combinat/designs/twographs.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def complement(self):
sage: is_twograph(pc)
True
"""
return super(TwoGraph, self).complement(uniform=True)
return super().complement(uniform=True)


def taylor_twograph(q):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/dyck_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def _repr_list(self) -> str:
sage: DyckWord('(())')
[1, 1, 0, 0]
"""
return super(DyckWord, self)._repr_()
return super()._repr_()

def _repr_lattice(self, type=None, labelling=None, underpath=True) -> str:
r"""
Expand Down
8 changes: 4 additions & 4 deletions src/sage/combinat/fqsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def G_to_G_on_basis(t):
else:
return self.coerce_map_from(G) * phi

return super(FQSymBasis_abstract, self)._coerce_map_from_(R)
return super()._coerce_map_from_(R)

@cached_method
def an_element(self):
Expand Down Expand Up @@ -476,7 +476,7 @@ def __getitem__(self, r):
r = list(r)
elif r == 1:
r = [1]
return super(FreeQuasisymmetricFunctions.F, self).__getitem__(r)
return super().__getitem__(r)

def degree_on_basis(self, t):
"""
Expand Down Expand Up @@ -787,7 +787,7 @@ def __getitem__(self, r):
r = list(r)
elif r == 1:
r = [1]
return super(FreeQuasisymmetricFunctions.G, self).__getitem__(r)
return super().__getitem__(r)

def _G_to_F_on_basis(self, w):
r"""
Expand Down Expand Up @@ -1005,7 +1005,7 @@ def __getitem__(self, r):
r = list(r)
elif r == 1:
r = [1]
return super(FreeQuasisymmetricFunctions.M, self).__getitem__(r)
return super().__getitem__(r)

def _F_to_M_on_basis(self, w):
r"""
Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/free_dendriform_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def __classcall_private__(cls, R, names=None):

if R not in Rings():
raise TypeError("argument R must be a ring")
return super(FreeDendriformAlgebra, cls).__classcall__(cls, R,
names)
return super().__classcall__(cls, R, names)

def __init__(self, R, names=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/free_prelie_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def __classcall_private__(cls, R, names=None):
if R not in Rings():
raise TypeError("argument R must be a ring")

return super(FreePreLieAlgebra, cls).__classcall__(cls, R, names)
return super().__classcall__(cls, R, names)

def __init__(self, R, names=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/fully_commutative_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ def __classcall_private__(cls, data):
group = data
else:
group = CoxeterGroup(data)
return super(cls, FullyCommutativeElements).__classcall__(cls, group)
return super().__classcall__(cls, group)

def __init__(self, coxeter_group):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/gelfand_tsetlin_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def __classcall_private__(cls, n=None, k=None, strict=False, top_row=None):
if n is not None and n != len(top_row):
raise ValueError("n must be the length of the specified top row")
return GelfandTsetlinPatternsTopRow(top_row, strict)
return super(GelfandTsetlinPatterns, cls).__classcall__(cls, n, k, strict)
return super().__classcall__(cls, n, k, strict)

def __init__(self, n, k, strict):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/grossman_larson_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __classcall_private__(cls, R, names=None):

if R not in Rings():
raise TypeError("argument R must be a ring")
return super(GrossmanLarsonAlgebra, cls).__classcall__(cls, R, names)
return super().__classcall__(cls, R, names)

def __init__(self, R, names=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/hillman_grassl.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def conjugate(self):
sage: c.parent()
Weak Reverse Plane Partitions
"""
C = super(WeakReversePlanePartition, self).conjugate()
C = super().conjugate()
return WeakReversePlanePartition(C)

def hillman_grassl_inverse(self):
Expand Down Expand Up @@ -437,7 +437,7 @@ def __classcall_private__(cls, shape=None, **kwds):
# from sage.combinat.partition import Partition
# return RibbonShapedTableaux_shape(Partition(shape))

return super(WeakReversePlanePartitions, cls).__classcall__(cls, **kwds)
return super().__classcall__(cls, **kwds)

def __init__(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/integer_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ def __classcall_private__(cls, n, comp):
sage: IntegerVectors(4, [2,1]) is IntegerVectors(int(4), (2,1))
True
"""
return super(IntegerVectors_nnondescents, cls).__classcall__(cls, n, tuple(comp))
return super().__classcall__(cls, n, tuple(comp))

def __init__(self, n, comp):
"""
Expand Down
9 changes: 4 additions & 5 deletions src/sage/combinat/k_regular_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ def __init__(self, parent, mu, left=None, right=None):
:doc:`k-regular sequence <k_regular_sequence>`,
:class:`kRegularSequenceSpace`.
"""
super(kRegularSequence, self).__init__(
parent=parent, mu=mu, left=left, right=right)
super().__init__(parent=parent, mu=mu, left=left, right=right)

def _repr_(self):
r"""
Expand Down Expand Up @@ -828,8 +827,8 @@ def __normalize__(cls, k, coefficient_ring, **kwds):
{0, 1}
"""
from sage.arith.srange import srange
nargs = super(kRegularSequenceSpace, cls).__normalize__(
coefficient_ring, alphabet=srange(k), **kwds)
nargs = super().__normalize__(coefficient_ring,
alphabet=srange(k), **kwds)
return (k,) + nargs

def __init__(self, k, *args, **kwds):
Expand Down Expand Up @@ -863,7 +862,7 @@ def __init__(self, k, *args, **kwds):
:class:`kRegularSequence`.
"""
self.k = k
super(kRegularSequenceSpace, self).__init__(*args, **kwds)
super().__init__(*args, **kwds)

def __reduce__(self):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/knutson_tao_puzzles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ def __classcall_private__(cls, puzzle_pieces, max_letter=None):
puzzle_pieces = BK_pieces(max_letter)
else:
raise ValueError("max_letter needs to be specified")
return super(KnutsonTaoPuzzleSolver, cls).__classcall__(cls, puzzle_pieces)
return super().__classcall__(cls, puzzle_pieces)

def __call__(self, lamda, mu, algorithm='strips'):
r"""
Expand Down
5 changes: 3 additions & 2 deletions src/sage/combinat/lr_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self, parent, t):
"""
self._shape = parent._shape
self._weight = parent._weight
super(LittlewoodRichardsonTableau, self).__init__(parent, list(t))
super().__init__(parent, list(t))

def check(self):
r"""
Expand Down Expand Up @@ -127,14 +127,15 @@ def check(self):
...
ValueError: weight of the parent does not agree with the weight of the tableau
"""
super(LittlewoodRichardsonTableau, self).check()
super().check()
if not [i for a in self.parent()._weight for i in a] == self.weight():
raise ValueError("weight of the parent does not agree "
"with the weight of the tableau")
if not self.shape() == self.parent()._shape:
raise ValueError("shape of the parent does not agree "
"with the shape of the tableau")


class LittlewoodRichardsonTableaux(SemistandardTableaux):
r"""
Littlewood-Richardson tableaux.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/ncsym/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _element_constructor_(self, x):
"""
if isinstance(x, (list, tuple)):
x = SetPartition(x)
return super(NCSymBasis_abstract, self)._element_constructor_(x)
return super()._element_constructor_(x)


class NCSymOrNCSymDualBases(Category_realization_of_parent):
Expand Down
6 changes: 2 additions & 4 deletions src/sage/combinat/necklace.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ def __classcall_private__(cls, content):
sage: Necklaces([2,1,1]) is Necklaces(Composition([2,1,1]))
True
"""
if isinstance(content, Composition):
return super(Necklaces_evaluation, cls).__classcall__(cls, content)
else:
if not isinstance(content, Composition):
content = Composition(content)
return super(Necklaces_evaluation, cls).__classcall__(cls, content)
return super().__classcall__(cls, content)

def __init__(self, content):
r"""
Expand Down
Loading

0 comments on commit e3ababd

Please sign in to comment.