Sphinx autodoc with mypy type annotations
Asked Answered
D

1

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?

Dam answered 21/11, 2018 at 8:21 Comment(1)
Does this answer your question? How to automatically add parameter types in sphinx documentationConnoisseur
O
1

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

Olympium answered 5/10, 2022 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.