Skip to content

Commit 1b78c70

Browse files
committed
Fix syntax for tuple related type annotations
1 parent 61734cd commit 1b78c70

2 files changed

Lines changed: 24 additions & 28 deletions

File tree

src/sage/combinat/tamari_blossoming_tree.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@
2929
# https://www.gnu.org/licenses/
3030
# ****************************************************************************
3131
from collections.abc import Iterator
32+
from math import acos, cos, pi, sin
3233
from typing import Self
33-
from math import acos, cos, sin, pi
3434

3535
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
36-
from sage.combinat.binary_tree import from_tamari_sorting_tuple, BinaryTree
36+
from sage.combinat.binary_tree import BinaryTree, from_tamari_sorting_tuple
3737
from sage.combinat.dyck_word import DyckWords
3838
from sage.combinat.integer_lists.invlex import IntegerListsLex
39-
from sage.combinat.interval_posets import (TamariIntervalPoset,
40-
TamariIntervalPosets)
41-
from sage.combinat.ordered_tree import OrderedTree, LabelledOrderedTree
39+
from sage.combinat.interval_posets import TamariIntervalPoset, TamariIntervalPosets
40+
from sage.combinat.ordered_tree import LabelledOrderedTree, OrderedTree
4241
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
4342
from sage.misc.latex import latex
4443
from sage.misc.lazy_attribute import lazy_attribute
45-
from sage.misc.prandom import uniform, randrange
44+
from sage.misc.prandom import randrange, uniform
4645
from sage.plot.arc import arc
4746
from sage.plot.arrow import arrow2d
4847
from sage.plot.bezier_path import bezier_path
@@ -1473,10 +1472,9 @@ def aux(tree, isroot=False):
14731472
# at the root: one bud at the beginning or the end
14741473
if len(idx) != 1 or (idx[0] != 0 and idx[0] != len(tree) - 1):
14751474
return False
1476-
else:
1477-
# otherwise: two buds consecutive
1478-
if len(idx) != 2 or idx[1] - idx[0] != 1:
1479-
return False
1475+
# otherwise: two buds consecutive
1476+
elif len(idx) != 2 or idx[1] - idx[0] != 1:
1477+
return False
14801478
for st in tree:
14811479
if st and not aux(st): # an internal node failing the test
14821480
return False
@@ -1577,7 +1575,7 @@ def gen_comb(n: int, k: int) -> list[int]:
15771575
return s
15781576

15791577
@staticmethod
1580-
def cutting(cardlist: list[float], size: int) -> list[(float, int)]:
1578+
def cutting(cardlist: list[float], size: int) -> list[tuple[float, int]]:
15811579
"""
15821580
Utility function to generate the cutting ratio list according to a
15831581
list of (relative) count of objects of sizes from ``0`` to ``size``.
@@ -1621,7 +1619,7 @@ def cutting(cardlist: list[float], size: int) -> list[(float, int)]:
16211619
# check list size
16221620
if len(cardlist) != size + 1:
16231621
raise ValueError("invalid parameter: l does not have correct size.")
1624-
cutting: list[(float, int)] = []
1622+
cutting: list[tuple[float, int]] = []
16251623
for i in range(size + 1):
16261624
cutting.append((cardlist[i] * cardlist[size - i], i))
16271625
# sort with decreasing probability for efficient random generation
@@ -2004,13 +2002,12 @@ def __path_to_tree(path: list[int]) -> TamariBlossomingTree:
20042002
for step in path:
20052003
if step == 3: # new node
20062004
stack.append([0, []])
2007-
else: # depending on type
2008-
if stack[-1][0] < 2: # add bud
2009-
stack[-1][0] += 1
2010-
stack[-1][1].append([])
2011-
else: # subtree completed
2012-
subtree = stack.pop()[1]
2013-
stack[-1][1].append(subtree)
2005+
elif stack[-1][0] < 2: # add bud
2006+
stack[-1][0] += 1
2007+
stack[-1][1].append([])
2008+
else: # subtree completed
2009+
subtree = stack.pop()[1]
2010+
stack[-1][1].append(subtree)
20142011
# Get the tree (list of subtrees for the moment)
20152012
stack = stack[-1][1][0]
20162013
# pop the last bud, which is always the last child
@@ -2311,14 +2308,13 @@ def random_element(self) -> TamariBlossomingTree:
23112308
for step in path:
23122309
if step == 2: # new nodes
23132310
stack.append([0, []])
2314-
else: # depending on type
2315-
if stack[-1][0] == 0: # add two buds
2316-
stack[-1][0] = 1
2317-
stack[-1][1].append([])
2318-
stack[-1][1].append([])
2319-
else: # subtree completed
2320-
subtree = stack.pop()[1]
2321-
stack[-1][1].append(subtree)
2311+
elif stack[-1][0] == 0: # add two buds
2312+
stack[-1][0] = 1
2313+
stack[-1][1].append([])
2314+
stack[-1][1].append([])
2315+
else: # subtree completed
2316+
subtree = stack.pop()[1]
2317+
stack[-1][1].append(subtree)
23222318
tree = stack[-1][1]
23232319
tree.append([]) # add the extra bud besides the root
23242320
return TamariBlossomingTree._from_plane_tree(tree, skip_check=True,

src/sage/symbolic/series_impl.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ class SymbolicSeries:
66
def is_terminating_series(self) -> bool: ...
77
def truncate(self) -> Any: ...
88
def default_variable(self) -> Any: ...
9-
def coefficients(self, x: Any = None, sparse: bool = True) -> list[list[Any, int]] | list[Any]: ...
9+
def coefficients(self, x: Any = None, sparse: bool = True) -> list[tuple[Any, int]] | list[Any]: ...
1010
def power_series(self, base_ring: Any) -> Any: ...

0 commit comments

Comments
 (0)