Docformatter inappropriately removes newline between classes

未关闭
#414 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

Start by reproducing the report with the minimal Annotated class examples and docformatter 1.7.8, then trace the formatter’s handling of attribute docstrings and blank lines between classes. Compare the examples with and without a following method to narrow down the case. Done when formatting preserves the blank line between classes consistently with Black and the reported pre-commit deadlock is resolved.

由索引模型根据 Issue 内容生成。

描述

fresh

I am currently experiencing a pre-commit deadlock between Black and Docformatter , but only in a very specific case.

Consider the following:

from typing import Annotated, Any


class VisibleWhen:
    """Describe the condition that controls a parameter's visibility."""

    equals: Annotated[Any, dict(something=1)]
    """Value that makes the parameter visible."""


class TransformParameter:
    """Define an input parameter accepted by a transform."""

Docformatter is removing a newline from in between the docstring for the equals property and the TransformParameter class, causing a deadlock in pre-commit because black puts two blank lines between classes.

This appears to only affect classes that use Annotated, and only if one of the parameters to Annotated contains a callable at any point with a keyword argument. The property must also not be followed by any methods. For example, this has the same bug:

from typing import Annotated, Any


class VisibleWhen:
    """Describe the condition that controls a parameter's visibility."""

    equals: Annotated[Any, {"something": dict(something=1)}]
    """Value that makes the parameter visible."""


class TransformParameter:
    """Define an input parameter accepted by a transform."""

But this does not:

from typing import Annotated, Any


class VisibleWhen:
    """Describe the condition that controls a parameter's visibility."""

    equals: Annotated[Any, {"something": dict(something=1)}]
    """Value that makes the parameter visible."""

    def function(self):
        """Does a thing."""


class TransformParameter:
    """Define an input parameter accepted by a transform."""

I also found that in this scenario, it removes the newline between the classes:

from typing import Annotated, Any


class VisibleWhen:
    """Describe the condition that controls a parameter's visibility."""

    equals: Annotated[Any, {"something": dict(something=1)}]
    """Value that makes the parameter visible."""

    prop: Any
    """A description of the property."""


class TransformParameter:
    """Define an input parameter accepted by a transform."""

Versions and Config

I am using docformatter version 1.7.8. Below are my settings for both Black and Docformatter:

[tool.docformatter]
recursive = true
blank = true
black = true
in-place = true

[tool.black]
unstable = true
enable-unstable-feature = ["string_processing"]
主要语言
Python
星标
600
派生
107
平均合并
22 小时 15 分钟
30 天内合并 PR
12

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PyCQA/docformatter 的其他 Issue

查看 PyCQA/docformatter 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。