sphinx-doc / sphinx-doc/sphinx
napoleon: docstrings do not produce type annotations
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
As seen in this test:
sphinx.ext.napoleon results in rST with :type: at the end of each .. attribute:::
.. attribute:: attr1
Quick description of attr1
:type: Arbitrary type
However, for these to render correctly as type annotations, this should generate
.. attribute:: attr1
:type: Arbitrary type
Quick description of attr1
I think this is a historical accident - the :type: option for the attribute 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:

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/test_ext_napoleon_docstring.py at the referenced lines and inspect the rST produced by sphinx.ext.napoleon for attribute docstrings. The work is done when the :type: option appears with the attribute directive and renders as a type annotation rather than as a trailing field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100