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

numpydoc sections not represented as its own block, if first in docstring #214

Closed
machow opened this issue Oct 4, 2023 · 3 comments
Closed

Comments

@machow
Copy link
Contributor

machow commented Oct 4, 2023

Describe the bug

For a function with a docstring like this:

def f():
    """
    one liner, this isn't shown

    longer description, this isn't shown

    See Also
    --------
    [related function, this is shown](#related_function)
    """

griffe's numpydoc parses produces a single DocstringSectionText, with all the contents.

WDYT of editing this line of the numpydoc parse, to ensure any section marked with lines (----) is its own DocstringSectionText?

https://github.com/mkdocstrings/griffe/blob/main/src/griffe/docstrings/numpy.py#L816

This way, various sections like See Also will be in their own DocstringSectionText, regardless of whether they're...

  • sandwiched between two sections that are parsed (e.g. Parameters and Returns)
  • the first section of the docstring
  • after another section of docstring that doesn't get parsed
@pawamoy
Copy link
Member

pawamoy commented Oct 4, 2023

Definitely looks like a bug in the parser! Also, yeah, I was planning to add support for generic admonitions, just like in the Google parser.

@machow
Copy link
Contributor Author

machow commented Oct 5, 2023

I can work on a quick PR tomorrow for the numpydoc parser! Is DocstringSectionAdmonition the catch-all for unknown sections? I think because I focused initially on numpydoc format in quartodoc, I totally missed that this piece existed in the google style parser 😅

(guessing from this google parser line)

@pawamoy
Copy link
Member

pawamoy commented Oct 5, 2023

Is DocstringSectionAdmonition the catch-all for unknown sections?

Yes!

A PR would be awesome, thanks a lot :)

pawamoy pushed a commit that referenced this issue Jan 15, 2024
Previously, sections titled "See also" and others were not
recognized as sections, and therefore just parsed as regular text.
Now, such unknown sections will be parsed as admonitions.

In a previous breaking change, support for prose between sections
was removed: this change compensantes the breakage by allowing
users to use admonitions such as Note, Important, etc., to re-add
prose between sections thanks to admonitions.

This also further reduces the gap between Numpydoc and Google-style.

Issue #214: #214
PR #219: #219
Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
@pawamoy pawamoy closed this as completed Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants