Skip to content

Commit

Permalink
Trac #29083: first parameter of a normal method must be self
Browse files Browse the repository at this point in the history
as suggested by lgtm

URL: https://trac.sagemath.org/29083
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Jori Mäntysalo
  • Loading branch information
Release Manager committed Feb 9, 2020
2 parents 67a399e + 0620c10 commit 554fa02
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 61 deletions.
11 changes: 6 additions & 5 deletions src/sage/combinat/dyck_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -2801,15 +2801,16 @@ def area_dinv_to_bounce_area_map(self):
return DyckWord(image)

@combinatorial_map(name="Bounce-area to area-dinv")
def bounce_area_to_area_dinv_map(D):
def bounce_area_to_area_dinv_map(self):
r"""
Return the image of the Dyck word under the map which sends a
Dyck word with ``bounce`` equal to `r` and ``area`` equal to `s` to a
Dyck word with ``area`` equal to `r` and ``dinv`` equal to `s` .
This implementation uses a recursive method by saying that
the last entry in the area sequence of `D` is equal to the number of
touch points of the Dyck path minus 1 of the image of this map.
This implementation uses a recursive method by saying that the
last entry in the area sequence of the Dyck word ``self`` is
equal to the number of touch points of the Dyck path minus 1
of the image of this map.
The inverse of this map is :meth:`area_dinv_to_bounce_area_map`.
Expand Down Expand Up @@ -2837,7 +2838,7 @@ def bounce_area_to_area_dinv_map(D):
sage: DyckWord([1,0,1,0]).bounce_area_to_area_dinv_map()
[1, 1, 0, 0]
"""
aseq = D.to_area_sequence()
aseq = self.to_area_sequence()
out = []
zeros = []
for i in range(len(aseq)):
Expand Down
5 changes: 3 additions & 2 deletions src/sage/combinat/set_partition_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ def _repr_(self):
return "Ordered set partitions"

class Element(OrderedSetPartition):
def _richcmp_(left, right, op):
def _richcmp_(self, other, op):
"""
TESTS::
Expand All @@ -1381,7 +1381,8 @@ def _richcmp_(left, right, op):
sage: el1 <= el2, el1 >= el2, el2 <= el1 # indirect doctest
(False, True, True)
"""
return richcmp([sorted(s) for s in left], [sorted(s) for s in right], op)
return richcmp([sorted(s) for s in self],
[sorted(s) for s in other], op)

##########################################################
# Deprecations
Expand Down
27 changes: 13 additions & 14 deletions src/sage/combinat/tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -2463,8 +2463,7 @@ def reverse_bump(self, loc):
return SemistandardTableau(new_t), to_move
return Tableau(new_t), to_move


def bump_multiply(left, right):
def bump_multiply(self, other):
"""
Multiply two tableaux using Schensted's bump.
Expand All @@ -2482,18 +2481,18 @@ def bump_multiply(left, right):
sage: t.bump_multiply(t2)
[[1, 1, 2, 2, 3], [2, 2, 3, 5], [3, 4, 5], [4, 6, 6], [5]]
"""
if not isinstance(right, Tableau):
raise TypeError("right must be a Tableau")
if not isinstance(other, Tableau):
raise TypeError("other must be a Tableau")

row = len(right)
product = Tableau([list(a) for a in left]) # create deep copy of left
while row > 0:
row = len(other)
product = Tableau([list(a) for a in self]) # create deep copy of self
while row:
row -= 1
for i in right[row]:
for i in other[row]:
product = product.bump(i)
return product

def slide_multiply(left, right):
def slide_multiply(self, other):
"""
Multiply two tableaux using jeu de taquin.
Expand All @@ -2513,14 +2512,14 @@ def slide_multiply(left, right):
[[1, 1, 2, 2, 3], [2, 2, 3, 5], [3, 4, 5], [4, 6, 6], [5]]
"""
st = []
if len(left) == 0:
return right
if len(self) == 0:
return other
else:
l = len(left[0])
l = len(self[0])

for row in right:
for row in other:
st.append((None,)*l + row)
for row in left:
for row in self:
st.append(row)

from sage.combinat.skew_tableau import SkewTableau
Expand Down
14 changes: 9 additions & 5 deletions src/sage/combinat/words/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,12 +2067,15 @@ def area(self):
raise TypeError("the path must be closed to compute its area")
return abs(self._area_vh())

def _area_vh(path, x=0, y=0):
def _area_vh(self, x=0, y=0):
r"""
Returns the area of path, with starting point (x,y) using VH algorithm.
Return the area of ``self``, with starting point (x,y).
This is using VH algorithm.
INPUT:
x, y -- starting point
- x, y -- starting point (optional, default (0, 0))
EXAMPLES::
Expand All @@ -2085,12 +2088,13 @@ def _area_vh(path, x=0, y=0):
-3
REFERENCES:
Annie Lacasse Memoire.
"""
area = 0
a,b,A,B = path.parent().alphabet()
a, b, A, B = self.parent().alphabet()

for move in path:
for move in self:
if move == b:
area -= x
y += 1
Expand Down
44 changes: 23 additions & 21 deletions src/sage/modular/arithgroup/congroup_gammaH.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,17 @@ def generators(self, algorithm="farey"):
else:
raise ValueError("Unknown algorithm '%s' (should be either 'farey' or 'todd-coxeter')" % algorithm)

def _coset_reduction_data_first_coord(G):
def _coset_reduction_data_first_coord(self):
"""
Compute data used for determining the canonical coset
representative of an element of SL_2(Z) modulo G. This
function specifically returns data needed for the first part
of the reduction step (the first coordinate).
representative of an element of SL_2(Z) modulo ``self``.
This function specifically returns data needed for the first
part of the reduction step (the first coordinate).
INPUT:
G -- a congruence subgroup Gamma_0(N), Gamma_1(N), or Gamma_H(N).
``self`` -- a congruence subgroup Gamma_0(N), Gamma_1(N), or Gamma_H(N)
OUTPUT:
Expand All @@ -516,12 +517,12 @@ def _coset_reduction_data_first_coord(G):
EXAMPLES::
sage: G = Gamma0(12)
sage: sage.modular.arithgroup.congroup_gammaH.GammaH_class._coset_reduction_data_first_coord(G)
sage: G._coset_reduction_data_first_coord()
[(0, 12, 0), (1, 1, 1), (2, 2, 1), (3, 3, 1), (4, 4, 1), (1, 1, 5), (6, 6, 1),
(1, 1, 7), (4, 4, 5), (3, 3, 7), (2, 2, 5), (1, 1, 11)]
"""
H = [ int(x) for x in G._list_of_elements_in_H() ]
N = int(G.level())
H = [int(x) for x in self._list_of_elements_in_H()]
N = int(self.level())

# Get some useful fast functions for inverse and gcd
inverse_mod = get_inverse_mod(N) # optimal inverse function
Expand Down Expand Up @@ -572,16 +573,17 @@ def _coset_reduction_data_first_coord(G):

return reduct_data

def _coset_reduction_data_second_coord(G):
def _coset_reduction_data_second_coord(self):
"""
Compute data used for determining the canonical coset
representative of an element of SL_2(Z) modulo G. This
function specifically returns data needed for the second part
of the reduction step (the second coordinate).
representative of an element of SL_2(Z) modulo ``self``.
This function specifically returns data needed for the second
part of the reduction step (the second coordinate).
INPUT:
self
``self``
OUTPUT:
Expand Down Expand Up @@ -618,19 +620,20 @@ def _coset_reduction_data_second_coord(G):
sage: K == divisors(1200)
True
"""
H = G._list_of_elements_in_H()
N = G.level()
H = self._list_of_elements_in_H()
N = self.level()
v = { 1: [1] , N: H }
for d in [x for x in divisors(N) if x > 1 and x < N ]:
N_over_d = N // d
v[d] = [x for x in H if x % N_over_d == 1]
for d in divisors(N):
if 1 < d < N:
N_over_d = N // d
v[d] = [x for x in H if x % N_over_d == 1]
return v

@cached_method
def _coset_reduction_data(self):
"""
Compute data used for determining the canonical coset
representative of an element of SL_2(Z) modulo G.
representative of an element of SL_2(Z) modulo ``self``.
EXAMPLES::
Expand All @@ -640,8 +643,7 @@ def _coset_reduction_data(self):
([(0, 13, 0), (1, 1, 1), (2, 1, 1), (3, 1, 1), (4, 1, 1), (5, 1, 1), (6, 1, 1), (6, 1, 12), (5, 1, 12), (4, 1, 12), (3, 1, 12), (2, 1, 12), (1, 1, 12)], {1: [1], 13: [1, 12]})
"""
return (self._coset_reduction_data_first_coord(),
self._coset_reduction_data_second_coord())

self._coset_reduction_data_second_coord())

def _reduce_coset(self, uu, vv):
r"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/monoids/string_monoid_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self, S, x, check=True):
else:
raise TypeError("Argument x (= %s) is of the wrong type." % x)

def _richcmp_(left, right, op):
def _richcmp_(self, other, op):
"""
Compare two free monoid elements with the same parents.
Expand All @@ -121,7 +121,7 @@ def _richcmp_(left, right, op):
sage: S("01") < S("10")
True
"""
return richcmp(left._element_list, right._element_list, op)
return richcmp(self._element_list, other._element_list, op)

def _repr_(self):
"""
Expand Down
16 changes: 8 additions & 8 deletions src/sage/rings/polynomial/multi_polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ def _poly_class(self):
from sage.rings.polynomial.multi_polynomial_element import MPolynomial_polydict
return MPolynomial_polydict

def __eq__(left, right):
def __eq__(self, other):
"""
Check whether ``left`` is equal to ``right``.
Check whether ``self`` is equal to ``other``.
EXAMPLES::
sage: R = PolynomialRing(Integers(10), 'x', 4)
sage: loads(R.dumps()) == R
True
"""
if not is_MPolynomialRing(right):
if not is_MPolynomialRing(other):
return False
return ((left.base_ring(), left.ngens(),
left.variable_names(), left.term_order()) ==
(right.base_ring(), right.ngens(),
right.variable_names(), right.term_order()))
return ((self.base_ring(), self.ngens(),
self.variable_names(), self.term_order()) ==
(other.base_ring(), other.ngens(),
other.variable_names(), other.term_order()))

def __ne__(self , other):
"""
Expand All @@ -172,7 +172,7 @@ def __ne__(self , other):

def __hash__(self):
"""
Compute the hash of self.
Compute the hash of ``self``.
EXAMPLES::
Expand Down
8 changes: 4 additions & 4 deletions src/sage/structure/formal_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ def _latex_(self):
# sage.misc.misc.repr_lincomb and use instead:
# return sage.misc.misc.repr_lincomb([[t,c] for c,t in self], is_latex=True)

def _richcmp_(left, right, op):
def _richcmp_(self, other, op):
"""
Compare ``left`` and ``right``.
Compare ``self`` and ``other``.
INPUT:
- ``right`` -- a :class:`FormalSum` with the same parent
- ``other`` -- a :class:`FormalSum` with the same parent
- ``op`` -- a comparison operator
Expand All @@ -228,7 +228,7 @@ def _richcmp_(left, right, op):
sage: a == 0 # 0 is coerced into a.parent()(0)
False
"""
return richcmp(left._data, right._data, op)
return richcmp(self._data, other._data, op)

def _neg_(self):
"""
Expand Down

0 comments on commit 554fa02

Please sign in to comment.