在Python中记录类或方法很容易:
class Something:
""" Description of the class. """
def do_it(self):
""" Description of the method. """
pass
class_variable = 1 # How to comment?
@property
def give_me_some_special_dict(self):
""" doesn't work! Doc of general dict will be shown. """
return {}
Run Code Online (Sandbox Code Playgroud)
但是如何在API文档中记录字段或属性以供使用help?
我有一个模块,errors.py其中定义了几个全局常量(注意:我知道Python没有常量,但我已经使用UPPERCASE按惯例定义了它们).
"""Indicates some unknown error."""
API_ERROR = 1
"""Indicates that the request was bad in some way."""
BAD_REQUEST = 2
"""Indicates that the request is missing required parameters."""
MISSING_PARAMS = 3
Run Code Online (Sandbox Code Playgroud)
使用reStructuredText如何记录这些常量?正如你所看到的,我已经在他们上面列出了一个文档字符串,但我没有找到任何表明这样做的文档,我只是猜测它.