【发布时间】:2021-10-15 08:55:23
【问题描述】:
以pickle.dump() 和pickle.load() 函数为例。
如何指示/记录/文档字符串pickle.dump()接收的参数类型或pickle.load()返回的值的类型?
这是Google Style Python Docsting 的示例。如您所见,普通函数的参数类型和返回类型是静态的并且明确记录在案:
def function_with_types_in_docstring(param1, param2):
"""Example function with types documented in the docstring.
`PEP 484`_ type annotations are supported. If attribute, parameter, and
return types are annotated according to `PEP 484`_, they do not need to be
included in the docstring:
Args:
param1 (int): The first parameter.
param2 (str): The second parameter.
Returns:
bool: The return value. True for success, False otherwise.
.. _PEP 484:
https://www.python.org/dev/peps/pep-0484/
"""
但有时参数/返回类型是动态的。甚至 pickle.py 也没有提供记录其函数的参数/返回对象类型的示例。
【问题讨论】: