-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
napoleon: docstrings do not produce type annotations #7582
Comments
I found that adding this setting for napoleon in conf.py give me the desired result :
I can't find were I found this solution. |
Yes, it was overlooked on updating 2.4. But I don't know this is good for numpydoc because the format allows many kinds of type-hints like string. see https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard. They are not compatible with PEP 484 based type annotations. |
Does it matter if the type description is parseable as PEP 484? Presumably sphinx just spits our the raw text if parsing fails. |
There are two worries. 1) A variable declaration in To be clear, I don't object to your idea strongly. I understand current formatting is not good, as you said. |
I reconsidered this and I feel this does not harm nobody. So +1 for this. |
I don't think we should close this yet. The following code (derived from https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html#example-google) still produces the old output format: class Foo:
def __init__(self):
#: list(str): Doc comment *before* attribute, with type specified
self.attr4 = ['attr4'] I wasn't sure how to fix this - the hook for parsing the comment doesn't appear to have the capability to set option flags on directives. |
The comment notation is not a part of google style and numpy style. So it is not responsibility of napoleon extension. I consider another topic. Additionally, we have variable type annotations now in python 3.6. So I think not so worthy to support it. |
My worry is realized and causes #7808 . So I reverted #7583 in #7827. So we should reconsider this again.
|
I think many people use numpy-format type descriptions that is written by natural language, not compatible with PEP-484 style type annotations. So it would be better to add a new option to enable this feature. I can accept it if we'll reach a good name. |
As seen in this test:
sphinx/tests/test_ext_napoleon_docstring.py
Lines 46 to 75 in 6cb3391
sphinx.ext.napoleon
results inrST
with:type:
at the end of each.. attribute::
:However, for these to render correctly as type annotations, this should generate
I think this is a historical accident - the
:type:
option for theattribute directive was added only in Sphinx 2.4, but the
:type:` field has been around for a long time.Graphically, the approaches in the two code blocks above result in the two styles visible in this image:
The text was updated successfully, but these errors were encountered: