Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中记录类型参数?_Python_Python Sphinx_Docstring_Type Variables - Fatal编程技术网

如何在Python中记录类型参数?

如何在Python中记录类型参数?,python,python-sphinx,docstring,type-variables,Python,Python Sphinx,Docstring,Type Variables,我想记录一下T在这门课上的意思 from typing import Generic, TypeVar T = TypeVar('T') class A(Generic[T]): pass 我可以用T来记录T。\uuuu doc\uuu=“表示…”,但我可能想在几个不相关的类中使用T 对于给定的类/函数等,是否有任何标准的方法来记录它?理想情况下使用斯芬克斯和休息 我的想法与sphinx的:param:相同,但对于类型,按照的@tparam行,您可以通过多行字符串记录它,如下所示:

我想记录一下
T
在这门课上的意思

from typing import Generic, TypeVar

T = TypeVar('T')

class A(Generic[T]):
    pass
我可以用
T来记录
T
。\uuuu doc\uuu=“表示…”
,但我可能想在几个不相关的类中使用
T

对于给定的类/函数等,是否有任何标准的方法来记录它?理想情况下使用斯芬克斯和休息


我的想法与sphinx的
:param:
相同,但对于类型,按照的
@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__


你不能用多行字符串来记录文档吗?@blueriens我不明白你的评论。你能详细解释一下吗?我的意思是像文档字符串或多行字符串。人们用来做文档的常规材料。但是您可能需要更高级的东西?根据,关于它,您所能说的就是
TypeVar('T')#可以是任何东西
——也就是说,它是一个泛型。类
A
是从它派生的,但可能需要或假定它具有某些特定属性。您可以记录类
A
自己的文档中的内容。
help(A)