Python代码文档与测试:最佳实践指南
1. 代码文档风格
在Python开发中,良好的代码文档至关重要。目前,Sphinx支持三种不同的文档风格:原始的Sphinx风格、较新的NumPy风格和Google风格。
1.1 Sphinx风格
Sphinx风格使用了大量的reStructuredText角色,虽然有效,但使用过多会影响可读性。例如:
:param amount: The amount of eggs to return
:type amount: int
以下是使用Sphinx风格对类进行文档化的示例:
class Spam(object):
'''
The Spam object contains lots of spam
:param arg: The arg is used for ...
:type arg: str
:param `*args`: The variable arguments are used for ...
:param `**kwargs`: The keyword arguments are used for ...
:ivar arg: This is where we store arg
:vartype arg: str
'''
def __init__(self, arg, *args, **kwargs):
self.arg =
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



