7

Currently, I have some code that uses mypy type annotations like this:

def translate(self, text, mark_unknown=False, format=None, deformat='txt', reformat='txt'):
    # type: (Translator, str, bool, Optional[str], str, str) -> str

I want to document it with Sphinx's autodoc extension, but it appears that autodoc currently doesn't recognize these annotations, so these annotations don't show up in the generated documentation.

Is there any easy fix for this e.g. another extension or autodoc option, or must I write an actual docstring with the relevant information?

mzjn
  • 48,958
  • 13
  • 128
  • 248
Andi Qu
  • 186
  • 1
  • 10
  • 1
    Does this answer your question? [How to automatically add parameter types in sphinx documentation](https://stackoverflow.com/questions/49540656/how-to-automatically-add-parameter-types-in-sphinx-documentation) – NLindros Apr 15 '20 at 06:14

1 Answers1

1

The sphinx-autodoc-typehints project seems to have been developed for exactly this use case.

David Stansby
  • 1,703
  • 1
  • 15
  • 18