按照PEP 257格式化docstring。

docformatter的Python项目详细描述


格式化文档字符串以跟随PEP 257

Build status

功能

docformatter当前自动将docstring格式化为 PEP 257惯例的子集。以下是相关项目的报价 来自PEP 257。

  • 为保持一致性,请始终在docstring周围使用三重双引号。
  • 即使字符串适合一行,也使用三重引号。
  • 多行docstrings由摘要行组成,就像一行一样 docstring,后面跟着一个空行,后面跟着一个更详细的 描述。
  • 除非整个docstring适合一行,否则请放置右引号 自己一行。

docformatter还处理一些pep 8约定。

  • 不要编写依赖于有效尾随的字符串文本 空白。这样的尾随空白在视觉上是无法区分的 一些编辑(或者最近的一些,reindent.py)将对它们进行裁剪。

安装

来自PIP:

$ pip install --upgrade docformatter

示例

运行后:

$ docformatter --in-place example.py

此代码

"""   Here are some examples.

    This module docstring should be dedented."""deflaunch_rocket():"""Launch
the
rocket. Go colonize space."""deffactorial(x):'''

    Return x factorial.

    This uses math.factorial.

    '''importmathreturnmath.factorial(x)defprint_factorial(x):"""Print x factorial"""print(factorial(x))defmain():"""Main
    function"""print_factorial(5)iffactorial(10):launch_rocket()

格式化为此格式

"""Here are some examples.

This module docstring should be dedented.
"""deflaunch_rocket():"""Launch the rocket.

    Go colonize space.
    """deffactorial(x):"""Return x factorial.

    This uses math.factorial.
    """importmathreturnmath.factorial(x)defprint_factorial(x):"""Print x factorial."""print(factorial(x))defmain():"""Main function."""print_factorial(5)iffactorial(10):launch_rocket()

选项

下面是帮助输出:

usage: docformatter [-h] [-i | -c] [-r] [--wrap-summaries length]
                    [--wrap-descriptions length] [--blank]
                    [--pre-summary-newline] [--make-summary-multi-line]
                    [--force-wrap] [--range line line] [--version]
                    files [files ...]

Formats docstrings to follow PEP 257.

positional arguments:
  files                 files to format or '-' for standard in

optional arguments:
  -h, --help            show this help message and exit
  -i, --in-place        make changes to files instead of printing diffs
  -c, --check           only check and report incorrectly formatted files
  -r, --recursive       drill down directories recursively
  --wrap-summaries length
                        wrap long summary lines at this length; set to 0 to
                        disable wrapping (default: 79)
  --wrap-descriptions length
                        wrap descriptions at this length; set to 0 to disable
                        wrapping (default: 72)
  --blank               add blank line after description
  --pre-summary-newline
                        add a newline before the summary of a multi-line
                        docstring
  --make-summary-multi-line
                        add a newline before and after the summary of a one-
                        line docstring
  --force-wrap          force descriptions to be wrapped even if it may result
                        in a mess
  --range line line     apply docformatter to docstrings between these lines;
                        line numbers are indexed at 1
  --version             show program's version number and exit

可能退出代码:

  • 1-如果遇到任何错误
  • 3-如果需要格式化任何文件(在--checkmode下)

包装说明

docformatter将包装描述,但仅限于简单的情况。如果有文本 这看起来像一个项目符号/编号列表,docformatter将离开 原样描述:

- Item one.
- Item two.
- Item three.

这样可以防止包装把东西弄得一团糟的风险。强迫 甚至这些要包装的实例也使用--force-wrap

问题

可以在GitHub page上报告错误和修补程序。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在下面的多线程程序中出错   java获取com。jcraft。jsch。JSCHEException:通过TeamCity构建时身份验证失败   java在Spring+Hibernate中设置H2数据库而不使用XML文件会产生NullPointerException   java无法运行程序,权限被拒绝   设计方法:过程还是有大量数据的Java?   java sbt不支持的专业。在Jdk 1.7中执行时出现的小版本52.0错误   java随机(?)ElementNotVisibleException   java如何确定输入到文本字段中的时间是否在预先设定的两个打开和关闭时间范围内?   java Map reduce驱动程序代码不工作   Android java客户端突然停止   java J2ssh客户端经常断开连接   java动态标量子查询   java试图通过使用嵌套循环获取非重复数字。。(二维阵列)   使用java通知用户来自socket的新请求   java我们应该为DAO使用spring单例吗