Python 和 sphinx:多行 google 样式文档字符串中的项目符号列表
Python and sphinx: bullet point list in multiline google style docstring
我目前正在使用 Sphinx 记录我的 Python 项目。在文档字符串的多行部分包含项目符号列表时,我遇到了一个问题。
我想包括一个项目符号列表,但其中一项很长。我愿意:
- 通过 Sphinx 正确呈现项目符号列表
- 但我的代码也有关于行长度 (<79) 的 PEP8
你会建议我为这个文档字符串做什么:
class geography():
""" Class defining a geography (cities and distance matrix)
This class implements a geography with a list of named cities with their
associated coordinates in a plane. Helper functions enable to :
- give a visual representation of that geography
- give a visual representation of the distance matrix
- give a visual representation of a configuration, a configuration being the repartition of some or all cities in pools
...
最后一行超过 79 个字符。
然后通过 Sphinx 呈现评论。添加马车 return 只会破坏 Sphinx 中的项目符号列表。
你可以break the bulleted想怎么排就怎么排。只需将延续与前几行文本对齐,例如:
- give a visual representation of that geography
- give a visual representation of the distance matrix
- give a visual representation of a configuration, a configuration being the
repartition of some or all cities in pools
的解决方案非常完美。我只是想补充一点,它也适用于非项目符号列表。我对函数或方法的参数的评论有类似的问题。例如:
def permute_array(arr, seq):
""" Function to "square permute" a 2D array
This function's purpose is to enable distance matrices permutations. That
is, for example, permute both lines and columns of the array so as to
reorder a distance matrix.
Args:
arr (numpy array): the array to permute. It should be square of size n.
seq (iterable of int): a permutation of range(n) (should be of length n and contain every integer from 0 to n-1)
最后一行太长了。
但是,"same indentation level" 换行符只是破坏了漂亮的 sphinx 方法文档:
Args:
arr (numpy array): the array to permute. It should be square of size n.
seq (iterable of int): a permutation of range(n) (should be of length n
and contain every integer from 0 to n-1)
Badly built documentation
但是,用标识打破行就可以了。
Args:
arr (numpy array): the array to permute. It should be square of size n.
seq (iterable of int): a permutation of range(n) (should be of length n
and contain every integer from 0 to n-1)
Nicely built documentation
我目前正在使用 Sphinx 记录我的 Python 项目。在文档字符串的多行部分包含项目符号列表时,我遇到了一个问题。
我想包括一个项目符号列表,但其中一项很长。我愿意:
- 通过 Sphinx 正确呈现项目符号列表
- 但我的代码也有关于行长度 (<79) 的 PEP8
你会建议我为这个文档字符串做什么:
class geography():
""" Class defining a geography (cities and distance matrix)
This class implements a geography with a list of named cities with their
associated coordinates in a plane. Helper functions enable to :
- give a visual representation of that geography
- give a visual representation of the distance matrix
- give a visual representation of a configuration, a configuration being the repartition of some or all cities in pools
...
最后一行超过 79 个字符。
然后通过 Sphinx 呈现评论。添加马车 return 只会破坏 Sphinx 中的项目符号列表。
你可以break the bulleted想怎么排就怎么排。只需将延续与前几行文本对齐,例如:
- give a visual representation of that geography
- give a visual representation of the distance matrix
- give a visual representation of a configuration, a configuration being the
repartition of some or all cities in pools
def permute_array(arr, seq):
""" Function to "square permute" a 2D array
This function's purpose is to enable distance matrices permutations. That
is, for example, permute both lines and columns of the array so as to
reorder a distance matrix.
Args:
arr (numpy array): the array to permute. It should be square of size n.
seq (iterable of int): a permutation of range(n) (should be of length n and contain every integer from 0 to n-1)
最后一行太长了。
但是,"same indentation level" 换行符只是破坏了漂亮的 sphinx 方法文档:
Args:
arr (numpy array): the array to permute. It should be square of size n.
seq (iterable of int): a permutation of range(n) (should be of length n
and contain every integer from 0 to n-1)
Badly built documentation
但是,用标识打破行就可以了。
Args:
arr (numpy array): the array to permute. It should be square of size n.
seq (iterable of int): a permutation of range(n) (should be of length n
and contain every integer from 0 to n-1)
Nicely built documentation