Skip to content

Commit 65f0975

Browse files
author
Release Manager
committed
gh-41133: some typing annotations in combinat/ mainly about `is_something` methods ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about URL: #41133 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Vincent Macri
2 parents b11c1b5 + 1fae623 commit 65f0975

20 files changed

+98
-98
lines changed

src/sage/combinat/alternating_sign_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ def number_of_negative_ones(self):
892892

893893
number_negative_ones = number_of_negative_ones
894894

895-
def is_permutation(self):
895+
def is_permutation(self) -> bool:
896896
"""
897897
Return ``True`` if ``self`` is a permutation matrix
898898
and ``False`` otherwise.

src/sage/combinat/binary_tree.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def node_to_str(bt):
644644
t_repr._baseline = t_repr._h - 1
645645
return t_repr
646646

647-
def _sort_key(self):
647+
def _sort_key(self) -> tuple:
648648
"""
649649
Return a tuple of nonnegative integers encoding the binary
650650
tree ``self``.
@@ -673,7 +673,7 @@ def _sort_key(self):
673673
resu = [l] + [u for t in self for u in t._sort_key()]
674674
return tuple(resu)
675675

676-
def is_empty(self):
676+
def is_empty(self) -> bool:
677677
"""
678678
Return whether ``self`` is empty.
679679
@@ -3627,7 +3627,7 @@ def builder(i, p):
36273627
for p in shuffle(W(l), W([shift + ri for ri in r])):
36283628
yield builder(shift, p)
36293629

3630-
def is_full(self):
3630+
def is_full(self) -> bool:
36313631
r"""
36323632
Return ``True`` if ``self`` is full, else return ``False``.
36333633
@@ -3797,7 +3797,7 @@ def prune(self):
37973797
return BinaryTree()
37983798
return BinaryTree([self[0].prune(), self[1].prune()])
37993799

3800-
def is_perfect(self):
3800+
def is_perfect(self) -> bool:
38013801
r"""
38023802
Return ``True`` if ``self`` is perfect, else return ``False``.
38033803
@@ -3844,7 +3844,7 @@ def is_perfect(self):
38443844
"""
38453845
return 2 ** self.depth() - 1 == self.number_of_nodes()
38463846

3847-
def is_complete(self):
3847+
def is_complete(self) -> bool:
38483848
r"""
38493849
Return ``True`` if ``self`` is complete, else return ``False``.
38503850

src/sage/combinat/cartesian_product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def __iterate__(self):
271271
"""
272272
return iter(self._mrange)
273273

274-
def is_finite(self):
274+
def is_finite(self) -> bool:
275275
"""
276276
The Cartesian product is finite if all of its inputs are
277277
finite, or if any input is empty.

src/sage/combinat/cluster_algebra_quiver/cluster_seed.py

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4833,7 +4833,7 @@ def SetToPath(T):
48334833
return ans
48344834

48354835

4836-
def is_LeeLiZel_allowable(T, n, m, b, c):
4836+
def is_LeeLiZel_allowable(T, n, m, b, c) -> bool:
48374837
"""
48384838
Check if the subset `T` contributes to the computation of the greedy element `x[m,n]` in the rank two `(b,c)`-cluster algebra.
48394839
@@ -4848,52 +4848,54 @@ def is_LeeLiZel_allowable(T, n, m, b, c):
48484848
True
48494849
"""
48504850
horiz = set(T).intersection(PathSubset(n, 0))
4851-
vert = set(T).symmetric_difference(horiz)
4852-
if len(horiz) == 0 or len(vert) == 0:
4851+
if not horiz:
48534852
return True
4854-
else:
4855-
Latt = SetToPath(PathSubset(n, m))
4856-
for u in horiz:
4857-
from sage.combinat.words.word import Word
4858-
from sage.modules.free_module_element import vector
4859-
WW = Word(Latt)
4860-
LattCycled = vector(WW.conjugate(Latt.index(u))).list()
4861-
for v in vert:
4862-
uv_okay = False
4863-
for A in range(LattCycled.index(v)):
4864-
EA = []
4865-
AF = copy(LattCycled)
4866-
for i in range(LattCycled.index(v), len(LattCycled)-1):
4867-
AF.pop()
4868-
AF.reverse()
4869-
for i in range(A+1):
4870-
EA.append(LattCycled[i])
4871-
AF.pop()
4872-
AF.reverse()
4873-
nAF1 = 0
4874-
for i in range(len(AF)):
4875-
if AF[i] % 2 == 1:
4876-
nAF1 += 1
4877-
nAF2 = 0
4878-
for i in range(len(AF)):
4879-
if AF[i] % 2 == 0 and AF[i] in vert:
4880-
nAF2 += 1
4881-
nEA2 = 0
4882-
for i in range(len(EA)):
4883-
if EA[i] % 2 == 0:
4884-
nEA2 += 1
4885-
nEA1 = 0
4886-
for i in range(len(EA)):
4887-
if EA[i] % 2 == 1 and EA[i] in horiz:
4888-
nEA1 += 1
4889-
if nAF1 == b*nAF2 or nEA2 == c*nEA1:
4890-
uv_okay = True
4891-
if not uv_okay:
4892-
return False
4853+
vert = set(T).symmetric_difference(horiz)
4854+
if not vert:
48934855
return True
48944856

4895-
4896-
def get_green_vertices(C):
4857+
Latt = SetToPath(PathSubset(n, m))
4858+
for u in horiz:
4859+
from sage.combinat.words.word import Word
4860+
from sage.modules.free_module_element import vector
4861+
WW = Word(Latt)
4862+
LattCycled = vector(WW.conjugate(Latt.index(u))).list()
4863+
for v in vert:
4864+
uv_okay = False
4865+
for A in range(LattCycled.index(v)):
4866+
EA = []
4867+
AF = copy(LattCycled)
4868+
for i in range(LattCycled.index(v), len(LattCycled) - 1):
4869+
AF.pop()
4870+
AF.reverse()
4871+
for i in range(A + 1):
4872+
EA.append(LattCycled[i])
4873+
AF.pop()
4874+
AF.reverse()
4875+
nAF1 = 0
4876+
for i in range(len(AF)):
4877+
if AF[i] % 2 == 1:
4878+
nAF1 += 1
4879+
nAF2 = 0
4880+
for i in range(len(AF)):
4881+
if AF[i] % 2 == 0 and AF[i] in vert:
4882+
nAF2 += 1
4883+
nEA2 = 0
4884+
for i in range(len(EA)):
4885+
if EA[i] % 2 == 0:
4886+
nEA2 += 1
4887+
nEA1 = 0
4888+
for i in range(len(EA)):
4889+
if EA[i] % 2 == 1 and EA[i] in horiz:
4890+
nEA1 += 1
4891+
if nAF1 == b * nAF2 or nEA2 == c * nEA1:
4892+
uv_okay = True
4893+
if not uv_okay:
4894+
return False
4895+
return True
4896+
4897+
4898+
def get_green_vertices(C) -> list[int]:
48974899
r"""
48984900
Get the green vertices from a matrix.
48994901
@@ -4914,7 +4916,7 @@ def get_green_vertices(C):
49144916
return [i for i, v in enumerate(C.columns()) if any(x > 0 for x in v)]
49154917

49164918

4917-
def get_red_vertices(C):
4919+
def get_red_vertices(C) -> list[int]:
49184920
r"""
49194921
Get the red vertices from a matrix.
49204922

src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ def cartan_matrix(self):
885885
# return CartanMatrix(cmat)
886886
return cmat
887887

888-
def is_irreducible(self):
888+
def is_irreducible(self) -> bool:
889889
"""
890890
Return ``True`` if ``self`` is irreducible.
891891
@@ -897,7 +897,7 @@ def is_irreducible(self):
897897
"""
898898
return self._info['irreducible']
899899

900-
def is_mutation_finite(self):
900+
def is_mutation_finite(self) -> bool:
901901
"""
902902
Return ``True`` if ``self`` is of finite mutation type.
903903
@@ -912,7 +912,7 @@ def is_mutation_finite(self):
912912
"""
913913
return self._info['mutation_finite']
914914

915-
def is_simply_laced(self):
915+
def is_simply_laced(self) -> bool:
916916
"""
917917
Return ``True`` if ``self`` is simply laced.
918918
@@ -935,7 +935,7 @@ def is_simply_laced(self):
935935
"""
936936
return self._info['simply_laced']
937937

938-
def is_skew_symmetric(self):
938+
def is_skew_symmetric(self) -> bool:
939939
"""
940940
Return ``True`` if the B-matrix of ``self`` is skew-symmetric.
941941
@@ -955,7 +955,7 @@ def is_skew_symmetric(self):
955955
"""
956956
return self._info['skew_symmetric']
957957

958-
def is_finite(self):
958+
def is_finite(self) -> bool:
959959
"""
960960
Return ``True`` if ``self`` is of finite type.
961961
@@ -974,7 +974,7 @@ def is_finite(self):
974974
"""
975975
return self._info['finite']
976976

977-
def is_affine(self):
977+
def is_affine(self) -> bool:
978978
"""
979979
Return ``True`` if ``self`` is of affine type.
980980
@@ -990,10 +990,9 @@ def is_affine(self):
990990
"""
991991
if self.is_irreducible():
992992
return self._info['affine']
993-
else:
994-
return False
993+
return False
995994

996-
def is_elliptic(self):
995+
def is_elliptic(self) -> bool:
997996
"""
998997
Return ``True`` if ``self`` is of elliptic type.
999998
@@ -1012,7 +1011,7 @@ def is_elliptic(self):
10121011
else:
10131012
return False
10141013

1015-
def properties(self):
1014+
def properties(self) -> None:
10161015
"""
10171016
Print a scheme of all properties of ``self``.
10181017

src/sage/combinat/colored_permutations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ def fixed_point_polynomial(self, q=None):
11261126
q = PolynomialRing(ZZ, 'q').gen(0)
11271127
return prod(q + d - 1 for d in self.degrees())
11281128

1129-
def is_well_generated(self):
1129+
def is_well_generated(self) -> bool:
11301130
r"""
11311131
Return if ``self`` is a well-generated complex reflection group.
11321132

src/sage/combinat/composition_tableau.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def weight(self):
199199
for row in self:
200200
for i in row:
201201
w[i] += 1
202-
return Composition([w[i] for i in range(1, self.size()+1)])
202+
return Composition([w[i] for i in range(1, self.size() + 1)])
203203

204204
def descent_set(self):
205205
r"""
@@ -253,7 +253,7 @@ def shape_partition(self):
253253
"""
254254
return Partition(sorted((len(row) for row in self), reverse=True))
255255

256-
def is_standard(self):
256+
def is_standard(self) -> bool:
257257
r"""
258258
Return ``True`` if ``self`` is a standard composition tableau and
259259
``False`` otherwise.

src/sage/combinat/constellation.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def __hash__(self):
232232
raise ValueError("cannot hash mutable constellation")
233233
return hash(tuple(self._g))
234234

235-
def set_immutable(self):
235+
def set_immutable(self) -> None:
236236
r"""
237237
Do nothing, as ``self`` is already immutable.
238238
@@ -245,7 +245,7 @@ def set_immutable(self):
245245
"""
246246
self._mutable = False
247247

248-
def is_mutable(self):
248+
def is_mutable(self) -> bool:
249249
r"""
250250
Return ``False`` as ``self`` is immutable.
251251
@@ -429,7 +429,7 @@ def mutable_copy(self):
429429

430430
# GENERAL PROPERTIES
431431

432-
def is_connected(self):
432+
def is_connected(self) -> bool:
433433
r"""
434434
Test of connectedness.
435435
@@ -444,10 +444,9 @@ def is_connected(self):
444444
"""
445445
if self._connected:
446446
return True
447-
else:
448-
return perms_are_connected(self._g, self.degree())
447+
return perms_are_connected(self._g, self.degree())
449448

450-
def connected_components(self):
449+
def connected_components(self) -> list:
451450
"""
452451
Return the connected components.
453452
@@ -946,7 +945,7 @@ def __init__(self, length, degree, sym=None, connected=True):
946945

947946
self._connected = bool(connected)
948947

949-
def is_empty(self):
948+
def is_empty(self) -> bool:
950949
r"""
951950
Return whether this set of constellations is empty.
952951
@@ -961,7 +960,7 @@ def is_empty(self):
961960
"""
962961
return self._connected and self._length == 1 and self._degree > 1
963962

964-
def __contains__(self, elt):
963+
def __contains__(self, elt) -> bool:
965964
r"""
966965
TESTS::
967966

src/sage/combinat/crystals/littelmann_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def weight(x):
835835
return sum(q**(c[0].energy_function()) * B.sum(B(weight(b)) for b in c) for c in C)
836836
return B.sum(q**(b.energy_function()) * B(weight(b)) for b in self)
837837

838-
def is_perfect(self, level=1):
838+
def is_perfect(self, level=1) -> bool:
839839
r"""
840840
Check whether the crystal ``self`` is perfect (of level ``level``).
841841

src/sage/combinat/crystals/pbw_datum.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ class PBWDatum():
8686
self.long_word == other_PBWDatum.long_word and
8787
self.lusztig_datum == other_PBWDatum.lusztig_datum)
8888

89-
def is_equivalent_to(self, other_pbw_datum):
89+
def is_equivalent_to(self, other_pbw_datum) -> bool:
9090
r"""
9191
Return whether ``self`` is equivalent to ``other_pbw_datum``.
92-
modulo the tropical Plücker relations.
92+
93+
Here equivalent means modulo the tropical Plücker relations.
9394

9495
EXAMPLES::
9596

0 commit comments

Comments
 (0)