Skip to content

Properly document iterable (or generator) returns #1852

Open

Description

@hyanwong

At the moment the docstring of the functions tskit.all_tree_shapes and tskit.all_tree_labellings claims the :rtype: is a tskit.Tree, but it's actually an iterator over trees (or more specifically a generator of trees).

While aiming to correct this, I also notice that the rtype for TreeSequence.trees() is (wrongly, surely?)

:rtype: collections.abc.Iterable, :class:`Tree`

whereas the rtype of TreeSequence.coiterate() is

:rtype: iter(:class:`Interval`, :class:`Tree`, :class:`Tree`)

So I guess we should standardise on a return type for all these functions, for instance we could use annotations

    def trees(
        ...
    ) -> Iterator[Tree]:
        ...

    def coiterate(
        ...
    ) -> Iterator[Tuple(Interval, Tree, Tree]]:
        ...

I haven't made this into a PR because it's unclear to me if we should be using typing.Iterable or collections.abc.Iterable (see e.g. https://docs.python.org/3/library/typing.html#typing.Iterable which says that the typing version with [] is deprecated as of python 3.9). Also there's Iterable, Iterator, and Generator, so I guess we need to pick which is the correct one? If we decide on which is the correct version, I'll make a PR.

Activity

  1. jeromekelleher commented on Oct 25, 2021

    @jeromekelleher
    Member

    It's very messy and I think it'll take a long time to get all this sorted out. In the meantime I don't think any of this really stops people getting work done. Ultimately we'll want to give proper type annotations I think, but I'd rather let the technology and ecosystems mature a bit more before putting much effort into it.

  2. added
    Infrastructure and tools
    on Oct 25, 2021
  3. hyanwong commented on Oct 25, 2021

    @hyanwong
    MemberAuthor

    Yep, I just wanted to correct the combinatorics values to something - don't much care what.

  4. jeromekelleher commented on Oct 25, 2021

    @jeromekelleher
    Member

    Pick one of the existing conventions, I don't mind which.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Infrastructure and toolsdocumentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions