OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Extract Google style docstring into dataclass using Sphinx Napoleon

  • Thread starter Thread starter Intrastellar Explorer
  • Start date Start date
I

Intrastellar Explorer

Guest
I am trying to programmatically ingest ("reflect") Google style docstrings. I am using sphinx.ext.napoleon, as seemingly not many tools do this. I am following this example with the below function:

Code:
from sphinx.ext.napoleon import Config, GoogleDocstring


def foo(arg: int | None = 5) -> None:
    """Stub summary.

    Args:
        arg(int): Optional integer defaulted to 5.
    """


docstring = GoogleDocstring(foo.__doc__)
print(docstring)

However, my usage doesn't automagically convert the printed output to reST style like the Sphinx example does.

So this leads me to my question. How can one programmatically ingest the summary, extended description, arg names, and arg descriptions from a Google Style docstring? Ideally they are converted into some sort of data structure (e.g. dict or dataclass).
<p>I am trying to programmatically ingest ("reflect") Google style docstrings. I am using <code>sphinx.ext.napoleon</code>, as seemingly not many tools do this. I am following <a href="https://github.com/sphinx-doc/sphinx/blob/v7.3.7/sphinx/ext/napoleon/docstring.py#L120-L146" rel="nofollow noreferrer">this example</a> with the below function:</p>
<pre class="lang-py prettyprint-override"><code>from sphinx.ext.napoleon import Config, GoogleDocstring


def foo(arg: int | None = 5) -> None:
"""Stub summary.

Args:
arg(int): Optional integer defaulted to 5.
"""


docstring = GoogleDocstring(foo.__doc__)
print(docstring)
</code></pre>
<p>However, my usage doesn't automagically convert the printed output to reST style like the Sphinx example does.</p>
<p>So this leads me to my question. How can one programmatically ingest the summary, extended description, arg names, and arg descriptions from a Google Style docstring? Ideally they are converted into some sort of data structure (e.g. <code>dict</code> or <code>dataclass</code>).</p>
 
Top