我想记录一下 T
在这个类中的含义
from typing import Generic, TypeVar
T = TypeVar('T')
class A(Generic[T]):
pass
我可以用 T.__doc__ = "Represents ..."
记录 T
但我可能想在几个不相关的地方使用 T
类。
对于给定的类/函数等,是否有任何标准的方法来记录它?理想情况下使用 sphinx 和 reST。
我正在考虑与 sphinx 的 :param:
处于同一级别的东西,但是对于类型,沿着 scaladoc 的路线的 @tparam
最佳答案
您可以按照建议的方式通过多行字符串记录它:
from typing import Generic, TypeVar
T = TypeVar('T')
class A(Generic[T]):
"""
Description of the class and his input T
Inputs:
T : what is T? the type of T
Returns:
res
"""
您可以将文档称为:
A.__doc__
或
help(A)
关于python - 如何在 Python 中记录类型参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56836909/