格式化文档字符串以遵循 PEP 257
项目描述
代码 |
|
文档字符串 |
|
GitHub |
|
派皮 |
|
格式化文档字符串以遵循PEP 257。
特征
docformatter自动格式化文档字符串以遵循 PEP 257 约定的子集。以下是 PEP 257 中引用的相关项目。
为了保持一致性,请始终在文档字符串周围使用三重双引号。
即使字符串适合一行,也会使用三引号。
多行文档字符串由一个摘要行组成,就像单行文档字符串一样,然后是一个空行,然后是更详细的描述。
除非整个文档字符串适合一行,否则将右引号单独放在一行上。
docformatter还处理一些 PEP 8 约定。
不要编写依赖重要尾随空格的字符串文字。这种尾随空格在视觉上无法区分,一些编辑器(或者最近的 reindent.py)会修剪它们。
请参阅read-the-docs上的完整文档。
安装
从点子:
$ pip install --upgrade docformatter
或者,如果你想使用 pyproject.toml 来配置 docformatter:
$ pip install --upgrade docformatter[tomli]
例子
运行后:
$ docformatter --in-place example.py
这段代码
""" Here are some examples.
This module docstring should be dedented."""
def launch_rocket():
"""Launch
the
rocket. Go colonize space."""
def factorial(x):
'''
Return x factorial.
This uses math.factorial.
'''
import math
return math.factorial(x)
def print_factorial(x):
"""Print x factorial"""
print(factorial(x))
def main():
"""Main
function"""
print_factorial(5)
if factorial(10):
launch_rocket()
被格式化成这个
"""Here are some examples.
This module docstring should be dedented.
"""
def launch_rocket():
"""Launch the rocket.
Go colonize space.
"""
def factorial(x):
"""Return x factorial.
This uses math.factorial.
"""
import math
return math.factorial(x)
def print_factorial(x):
"""Print x factorial."""
print(factorial(x))
def main():
"""Main function."""
print_factorial(5)
if factorial(10):
launch_rocket()
营销
你使用docformatter吗?你使用什么风格的文档字符串?在项目的README中添加一些徽章,让所有人都知道。
.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
:target: https://github.com/PyCQA/docformatter
.. image:: https://img.shields.io/badge/%20style-google-3666d6.svg
:target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings
.. image:: https://img.shields.io/badge/%20style-numpy-459db9.svg
:target: https://numpydoc.readthedocs.io/en/latest/format.html
.. image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
:target: https://www.sphinx-doc.org/en/master/usage/index.html
问题
可以在GitHub 页面上报告错误和补丁。