Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docstring return output with typing in sphinx #375

Closed
paddyroddy opened this issue Oct 18, 2024 · 5 comments · Fixed by #381
Closed

Improve docstring return output with typing in sphinx #375

paddyroddy opened this issue Oct 18, 2024 · 5 comments · Fixed by #381
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@paddyroddy
Copy link
Member

In addition, just now I experimented a bit with https://github.com/tox-dev/sphinx-autodoc-typehints and this could provide the kind of annotation we would like to see:

def vmap_galactic_ecliptic(
    nside: int,
    galactic: tuple[float, float] = (30, 90),
    ecliptic: tuple[float, float] = (20, 80),
) -> npt.NDArray[typing.Any]:
    """
    ...

    Returns
    -------
    A HEALPix :term:`visibility map`.

    """

Which produces:

image

Originally posted by @ntessore in #373 (comment)

@paddyroddy paddyroddy added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 18, 2024
@ntessore ntessore self-assigned this Oct 18, 2024
@ntessore
Copy link
Collaborator

I'm happy to experiment with this

@paddyroddy
Copy link
Member Author

@ntessore I'm looking at this as part of #188, have got something like:

Image

# -- autodoc -----------------------------------------------------------------

autodoc_typehints = "description"


# -- napoleon ----------------------------------------------------------------

napoleon_google_docstring = False
napoleon_use_rtype = False


# -- sphinx-autodoc-typehints ----------------------------------------------------------------

always_use_bars_union = True
typehints_use_rtype = False
typehints_defaults = "comma"

with these settings, but I can't work out how to get rid of the redundant Returns... Any idea?

@ntessore
Copy link
Collaborator

ntessore commented Oct 25, 2024

To be honest, I am starting to think perhaps having separate "returns" and "return type" sections is a feature, not a bug. For simple return types, this isn't the worst output:

Returns:
  The value of the thing.

Return type:
  int

Whereas for complicated situations, having both sections allows for much more nuance:

Returns:
  - a (int) -- The value of a. Only returned if return_a is true.    <  These are manually
  - b (float) -- The value of b. Only returned if return_b is true.  <  written out in the
  - c (bool) -- The value of c. Only returned if return_c is true.   <  "returns" section.

Return type:
  <some complicated mess that is impossible to understand, ideally suppressed>

@ntessore
Copy link
Collaborator

Perhaps a good question to answer first is whether the documentation of from_convergence() can be made human-readable using a number of @typing.overload?

@paddyroddy
Copy link
Member Author

Discussed in a call. Going to keep Returns and Return type. Can be addressed again in the future if we want.

@paddyroddy paddyroddy linked a pull request Oct 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants