-
-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support in third-party tools/lib and how to evolve the spec #463
Comments
Hi @pawamoy, thanks for opening this issue! I'm quite interested in Griffe; in particular because autodoc support is the main thing keeping many projects from moving away from Sphinx. Evolving the spec to address gaps in the spec or new use cases should be possible, assuming it's not too disruptive for existing users. Opening issues on this repo would be the way to go. Only if there's something big-picture or bc-breaking, it needs to be run by the numpy-discussion mailing list. |
Hey @rgommers, thanks for the very fast response 🙂 I can then try to summarize our findings in this issue first, and if needed move each item to its own issue.
The rest I forgot or is just standardization of the standards: finding a common denominator for all styles, or expanding each style to support everything supported in the others. For example Numpydoc has "See also" and "Methods" sections, while the Google-style does not. Currently "See also" and "Methods" have no special treatment in Griffe and are just parsed as admonitions, but in the future I'll probably add support for "Methods" in both Numpydoc and Google styles. |
I agree, this should not be a blocker. The deprecation directly is a simple admonition, so it has a Markdown equivalent - and we can consider changing it to a more neutral syntax or to show the equivalent Markdown (colon fence I guess?) as well.
This one is a little painful, also in Sphinx. Last times I tried things were not pretty. The most important thing that was missing was reasonable support for type aliases, because showing raw type annotations as html is often super unhelpful when you go beyond the basics and start needing overloads/unions/typevars. I'm not sure about using
I agree that that's unhelpful. The spec has these examples:
In practice I don't think that is done in NumPy or SciPy much (or at all), we've kind of settled on including the default value as part of the description rather than the type. We may be able to remove support for this.
In my understanding, it isn't. |
Hmm, that will depend on the Markdown implementation 🤔 I don't think admonitions are part of the Markdown spec (at least they're not in CommonMark) with markdown-callouts > DEPRECATED: **Deprecated since 1.6.0**
> `ndobj_old` will be removed in NumPy 2.0.0, it is replaced by
> `ndobj_new` because the latter works also with array subclasses. (chevrons not strictly necessary) with pymdown-extensions !!! danger "Deprecated since 1.6.0"
`ndobj_old` will be removed in NumPy 2.0.0, it is replaced by
`ndobj_new` because the latter works also with array subclasses. or with pymdownx blocks /// admonition | Deprecated since 1.6.0
type: danger
`ndobj_old` will be removed in NumPy 2.0.0, it is replaced by
`ndobj_new` because the latter works also with array subclasses.
/// They're all extensions of Python-Markdown. I can't speak for other implementations. The most readable is the markdown-callouts one, in my opinion. I think GFM has a similar, experimental feature for admonitions.
Yep, long type annotations are not pleasant to read. Not sure about Sphinx, but with MkDocs+mkdocstrings, if you declare a type alias and use it as return annotation, it will not be expanded when rendering docs. Even better, if you document this type alias (docstring below it), then the rendered return type will link to it and users will see its value (the raw type annotation, as written in the source, linking again to sub types/aliases, recursively, as long as they're documented).
That's the suggestion yes. I agree, it's not obvious what it means when reading the docstring. I cannot think of a better alternative that fits into the current syntax though 🤔
Ha, I personally support this way of documenting the default value, unfortunately some users would like to override the default value from the signature with some parse-able metadata in the docstring, notably for mutable defaults that are set in the function body instead of the signature to avoid bugs. The signature's default value is for example rendered in a "Default" table column with
This could be explained early and explicitly in the guide then! Thanks for your answers, that helps clearing my thoughts 🙂 |
Hey! I'm working on supporting generating API documentation with quarto.org (e.g. the python shiny API docs), so have a lot of time I can throw at supporting this! I wonder if a helpful approach might be framing issues in terms of what the numpydoc parser does right now. Returns section syntax always expects a typeOne question the shiny team asked was "how do we just document the already annotated return type, without having to write some arbitrary name in the returns section?". We settled on having them just use from numpydoc.docscrape import NumpyDocString
doc = """
Returns
-------
some_type
x : int
y :
: float
:
"""
NumpyDocString(doc)["Returns"] output:
Note that the last 3 return pieces are interpreted as a type description. Unlike the parameters section, there isn't really a way to say "I am not manually specifying the type" in the returns section. RE @rgommers point:
I wonder if it's helpful to reframe the question to these two:
Like with the parameters section, users in an interactive terminal will be able to see the return type in the function signature, so hopefully using something like Prose between sectionsRE @rgommers point to whether prose is allowed between sections
The numpydoc parser does not allow prose between sections, but the sphinx parser does (and sphinx is the one rendering the ultimate output). e.g. def f(x, y, z: str) -> int:
"""Some function
Parameters
----------
x: int
the x parameter
z:
cool
y: abc
nice
.. note::
I am a note
Returns
-----------
x :
Some description
""" renders in sphinx with a note between the Parameters and Returns section, while the numpydoc parser just puts the note text as a parameter name. Sphinx example numpydoc example from numpydoc.docscrape import NumpyDocString
doc = """Some function
Parameters
----------
x: int
the x parameter
z:
cool
y: abc
nice
.. note::
I am a note
Returns
-----------
x :
Some description
"""
list(NumpyDocString(doc).items()
It seems fair that this is maybe a weird edge case, and the numpydoc spec doesn't allow prose between sections! |
…ions on blank lines Breaking change: This change removes the docstring option `allow_section_blank_line` for the Numpydoc parser, and changes the parsing logic so that blank lines are now *always* allowed, in any number, between sections. Sections are now only delimited by section headers themselves. The result of these changes is that: **prose is not allowed in between Numpydoc sections anymore**, making the parser compliant with the Numpydoc style guide and its maintainers recommendations. PR #220: #220 Related to PR #219: #219 Numpydoc discussion: numpy/numpydoc#463
Hello, I'm maintaining a tool called Griffe which among other things is capable of parsing Numpydoc styled docstrings. It's used by mkdocstrings, to auto-generate HTML docs from Python source code in MkDocs sites.
With time, we discovered a few subtleties that are not specified, and a few use-cases that are not supported by the spec. Our parser therefore takes some liberties, or allows configuration, and I guess it would nice to give some feedback upstream, i.e. to you Numpydoc maintainers.
But first, I'd like to know if there's a preferred way for you to get this feedback, and if you're even OK with the possibility of evolving the spec. Are issues here OK? Should I mention someone in particular?
The text was updated successfully, but these errors were encountered: