带有 mypy 类型注释的 Sphinx autodoc

And*_* Qu 6 python python-sphinx autodoc mypy

目前,我有一些使用 mypy 类型注释的代码,如下所示:

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

我想用 Sphinx 的 autodoc 扩展来记录它,但似乎 autodoc 当前无法识别这些注释,因此这些注释不会出现在生成的文档中。

对此是否有任何简单的解决方法,例如另一个扩展或 autodoc 选项,或者我必须编写包含相关信息的实际文档字符串?

Dav*_*sby 1

sphinx-autodoc-typehints项目似乎正是针对此用例而开发的。