【发布时间】:2017-02-16 19:50:12
【问题描述】:
我们可以在python中使用docstring来表示函数参数的类型:
def f1(a):
"""
:param a: an input.
:type a: int
:return: the input integer.
:rtype: int
"""
return a
对于f1,autodoc 生成以下文档:
fun1(a)
Parameters : a (int) – an input.
Returns : the input integer.
Return type: int
在python 3中,类型也可以通过类型提示来指示:
def f2(a: int):
"""
:param a: an input.
:return: the input integer.
:rtype: int
"""
return a
当我们运行 autodoc 时,它通过参数声明来放置类型,而不是在描述中:
f2(a: int)
Parameters : a – an input.
Returns : the input integer.
Return type: int
是否可以使用注释而不是文档字符串将文档生成为f1?我正在使用python 3.6。谢谢!
【问题讨论】:
-
显然你可以写出你想要的代码。
-
查看:github.com/sphinx-doc/sphinx/issues/1968 可能通过此更改,您可以获得开箱即用的类型注释支持
-
是的,希望 Sphinx 很快会支持它。
标签: python python-3.x autodoc