From 21531b5bd1262155131eb9a8ccf7bbd0a270c1b6 Mon Sep 17 00:00:00 2001 From: Zuolin Cheng Date: Wed, 2 Dec 2026 14:03:48 -0800 Subject: [PATCH 1/2] Document tree enumeration return types as iterators --- python/tskit/combinatorics.py | 9 ++++++--- python/tskit/trees.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/python/tskit/combinatorics.py b/python/tskit/combinatorics.py index a1eba56e06..03ca06020f 100644 --- a/python/tskit/combinatorics.py +++ b/python/tskit/combinatorics.py @@ -667,7 +667,8 @@ def all_trees(num_leaves, span=1): :param int num_leaves: The number of leaves of the tree to generate. :param float span: The genomic span of each returned tree. - :rtype: tskit.Tree + :return: An iterator yielding a :class:`tskit.Tree` for each labelled tree. + :rtype: :class:`collections.abc.Iterator` """ for rank_tree in RankTree.all_labelled_trees(num_leaves): yield rank_tree.to_tsk_tree(span=span) @@ -679,7 +680,8 @@ def all_tree_shapes(num_leaves, span=1): :param int num_leaves: The number of leaves of the tree to generate. :param float span: The genomic span of each returned tree. - :rtype: tskit.Tree + :return: An iterator yielding a :class:`tskit.Tree` for each shape. + :rtype: :class:`collections.abc.Iterator` """ for rank_tree in RankTree.all_unlabelled_trees(num_leaves): default_labelling = rank_tree.label_unrank(0) @@ -695,7 +697,8 @@ def all_tree_labellings(tree, span=1): :param tskit.Tree tree: The tree used to generate labelled trees of the same shape. :param float span: The genomic span of each returned tree. - :rtype: tskit.Tree + :return: An iterator yielding a :class:`tskit.Tree` for each labelling. + :rtype: :class:`collections.abc.Iterator` """ rank_tree = RankTree.from_tsk_tree(tree) for labelling in RankTree.all_labellings(rank_tree): diff --git a/python/tskit/trees.py b/python/tskit/trees.py index 168cead7e0..8ec00dc726 100644 --- a/python/tskit/trees.py +++ b/python/tskit/trees.py @@ -5221,7 +5221,7 @@ def trees( is only relevant when trees have multiple roots. :param bool sample_counts: Deprecated since 0.2.4. :return: An iterator over the Trees in this tree sequence. - :rtype: collections.abc.Iterable, :class:`Tree` + :rtype: :class:`collections.abc.Iterator` """ # tracked_leaves, leaf_counts and leaf_lists are deprecated aliases # for tracked_samples, sample_counts and sample_lists respectively. @@ -5258,7 +5258,7 @@ def coiterate(self, other, **kwargs): current tree sequence, and the first tree of the ``other`` tree sequence; the ``.left`` attribute of the initial interval will be 0 and the ``.right`` attribute will be the smallest non-zero breakpoint of the 2 tree sequences. - :rtype: iter(:class:`Interval`, :class:`Tree`, :class:`Tree`) + :rtype: :class:`collections.abc.Iterator` """ if self.sequence_length != other.sequence_length: From 6607dc4972a43f44b305c66ebb3a12c567960a0a Mon Sep 17 00:00:00 2001 From: Zuolin Cheng Date: Wed, 2 Dec 2026 14:38:24 -0800 Subject: [PATCH 2/2] Preserve class links in tree iterator return descriptions --- python/tskit/trees.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/tskit/trees.py b/python/tskit/trees.py index 8ec00dc726..e8191dcd85 100644 --- a/python/tskit/trees.py +++ b/python/tskit/trees.py @@ -5220,7 +5220,7 @@ def trees( those subtending meaningful topology, set this to 2. This value is only relevant when trees have multiple roots. :param bool sample_counts: Deprecated since 0.2.4. - :return: An iterator over the Trees in this tree sequence. + :return: An iterator over the :class:`Tree` objects in this tree sequence. :rtype: :class:`collections.abc.Iterator` """ # tracked_leaves, leaf_counts and leaf_lists are deprecated aliases @@ -5253,7 +5253,8 @@ def coiterate(self, other, **kwargs): :meth:`.trees` method when constructing the returned trees. :return: An iterator returning successive tuples of the form - ``(interval, tree_self, tree_other)``. For example, the first item returned + ``(interval, tree_self, tree_other)``, with an :class:`Interval` and + two :class:`Tree` objects. For example, the first item returned will consist of an tuple of the initial interval, the first tree of the current tree sequence, and the first tree of the ``other`` tree sequence; the ``.left`` attribute of the initial interval will be 0 and the ``.right``