sphinx-doc / sphinx-doc/sphinx

napoleon: docstrings do not produce type annotations

Open
#7,582 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

extensions:napoleon type:proposal
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

As seen in this test:

https://github.com/sphinx-doc/sphinx/blob/6cb3391bb88be1091f3c685277bdd52a4730c92a/tests/test_ext_napoleon_docstring.py#L46-L75

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:
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.