建议有功能:
def do_product(a: int, b: int) -> int:
return a * b
然后我开始记录我的功能:
def do_product(a: int, b: int) -> int:
"""This function gets two integers and returns the product
:param a: first integer
:param b: second integer
:return: return the product of a and b"""
return a * b
当我使用 Sphinx 时,我使用 sphinx 的 sphinx-autodoc-typehints 扩展将类型提示导入到 API 文档中。这样做的好处是我在编程时只声明一次类型并且不能消除文档和函数声明之间的歧义。我目前正在处理一个 PR,要求我在文档字符串中声明类型。这看起来像这样:
def do_product(a: int, b: int) -> int:
"""This function gets two integers and returns the product
:param int a: first integer
:param int b: second integer
:return int: return the product of a and b"""
return a * b
这没有意义,因为这似乎是函数内声明的复制..