-
Notifications
You must be signed in to change notification settings - Fork 21
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
Return value section loses text in backticks #96
Comments
I don't think the returns section conforms to numpydoc style. It looks like the parser thinks the description is type information. Do you know if that worked with sphinx? numpydoc has two styles for return sections:
https://numpydoc.readthedocs.io/en/latest/format.html#returns |
In all of our code, the functions have a return type annotation, like this: def f(x: int) -> str:
"""
<docstring text here>
Returns
--------
A string representation of `x`.
"""
... Can quartodoc use that return type information? Perhaps the resulting markdown could look something like this:
With the numpydoc's second style of return documentation, does that mean the returned value is a tuple? In practice, I think that is very uncommon, at least in our code. For us, if we return a tuple, I think it makes sense to document that the return value is a tuple with specified types, instead of using a table. So if we had a function like this: def g(x: int) -> tuple(int, str | None):
"""
<docstring text here>
Returns
--------
A tuple where the first value is a return code, and the second value is an error message, or `None` if no error.
"""
... The resulting markdown could be like this:
|
quartodoc uses numpydoc style, so if numpydoc supports it, then we should support it too. For the example you gave, it seems like you are using what numpydoc parses as the from numpydoc.docscrape import NumpyDocString
ds = NumpyDocString(
"""
<docstring text here>
Returns
--------
A tuple where the first value is a return code, and the second value is an error message, or `None` if no error.
"""
)
ds["Returns"]
It's surprising numpydoc all return styles involve writing out the type. I want to be careful not to deviate from numpydoc style, but I think you should be able to override the render of DocstringSectionReturns |
From #90 (but that comment was really about this issue):
I don't want backticks in the type column. I actually don't want a table, but even when I provided a customized For example, see https://shiny.rstudio.com/py/api/ui.notification_show.html. This should say "The notification's |
tl;dr does this syntax work for you?Using this syntax seems to work with the griffe parser (cf mkdocstrings/griffe#137; please raise an issue there if you are concerned about stability of the behavior):
Examplefile: test_func.py def f(x) -> int:
"""
Returns
-------
:
the description
""" preview(get_object("test_func.f").docstring)
BackgroundIt sounds like there are two issues at play:
It looks like griffe handles automatically inferring the return type, when you just use "some_name: " in returns with no type on the right-hand side. from griffe.dataclasses import Docstring
from griffe.docstrings.parsers import parse_numpy
from quartodoc import preview
doc = Docstring("""
Returns
-------
:
some `backtick` thing
"""
)
preview(parse_numpy(doc))
This is not what numpydoc does (since it only uses the docstring), but it makes sense to me that griffe might do some more nuanced handling here, since it does have return type information: from numpydoc.docscrape import NumpyDocString
ds = NumpyDocString(
"""
<docstring text here>
Returns
--------
:
A tuple where the first value is a return code, and the second value is an error message, or `None` if no error.
"""
)
ds["Returns"]
|
@machow I just noticed that the Return value here is truncated: https://shiny.rstudio.com/py/api/render.plot.html (compare to the docstring Should we be going through the py-shiny repo and changing all the docstrings to have the dummy |
Yeah -- writing the docstrings like this should fix it, and pull in the correct return type: def f(x) -> int:
"""
Returns
-------
:
the description
""" |
Update: I've updated the docstrings in shiny to use |
There's now a (rough) example in the docs https://machow.github.io/quartodoc/get-started/docstring-examples.html#returns-using-type-annotation |
For example, the input text in the docstring is this (https://github.com/rstudio/py-shiny/blob/8cafc4470691961a8f994bcfc819d13d19f9deed/shiny/ui/_notification.py#L54-L56):
However, the output qmd looks like this:
And the HTML:
I tried changing the double backticks around
id
to single backticks, but it made no difference.The text was updated successfully, but these errors were encountered: