Python: docstrings and type annotations

Having a function like:

def foo(x: int) -> float: return float(x) 

I would like to use a docstring of type NumPy, as shown below:

 def foo(x: int) -> float: """ Parameters ---------- x Input parameter Returns ------- The output value. """ return float(x) 

Note that:

  • I do not want to specify the parameter type again.
  • I do not want to specify the type of the return value again.
  • I would like this extension to be able to read annotated types (and write them to the generated HTML documentation).

Is there an Sphinx extension that supports this? Would you recommend a different syntax?

+7
python python-sphinx
source share
1 answer

Standard autodoc extension. The Napoleon extension supports Google and NumPy-style docstrings.

+1
source share

All Articles