Skip to content

Support for typing @overload annotation #442

Open

Description

@jpfeuffer

Problem Description

Some support for function overloads specified by @overload annotation in typestubs is missing. All functions that have it, are just shown with the general base implementation (*args, **kwds) instead of the declared and fully typed overloads.

Proposal

In the beginning, just one entry per overload would be nice.

Additional context

Trying to document a Cython extension that due to its C++ origin has typestubs with @overload annotations

Activity

  1. mhils commented on Sep 28, 2022

    @mhils
    Member

    pdoc heavily relies on dynamic analysis. As far as I know, you cannot access @overload signatures using that approach (the final function definition overwrites all previous ones). Implementing support using static analysis would be a major undertaking and introduce significant complexity. I think your request is by all means valid, but I'm afraid the answer here is to 1) use a different documentation generator, 2) not use @overload, or 3) live with it.

  2. jpfeuffer commented on Sep 29, 2022

    @jpfeuffer
    Author

    I see. That makes sense. Do you by chance know about any documentation tool that supports both typestubs and overloads 😅 It is surprisingly hard to find.

    Btw: It might be possible starting from 3.11.
    python/cpython#89263

  3. mhils commented on Sep 29, 2022

    @mhils
    Member

    Seems like this hasn't made it into 3.11 in time and will be in 3.12 the earliest.

    I see. That makes sense. Do you by chance know about any documentation tool that supports both typestubs and overloads

    I don't know, but Sphinx and maybe mkdocstrings have the largest ecosystems.

  4. jpfeuffer commented on Sep 29, 2022

    @jpfeuffer
    Author

    Yes, not in the help() function but maybe via the typing stdlib (typing.getOverloads()). The PR for that was merged early enough I think.

    Anyway, I give up for now and will revisit the whole thing in the very distant future again. (Sphinx autosummary/doc does not support type stubs at all and overloads only via docstrings and without descriptions of each overload).

    Thanks for considering!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions