Docformatter inappropriately removes newline between classes

Đang mở
#414 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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"]
Ngôn ngữ chính
Python
Star
600
Fork
107
Merge trung bình
22 giờ 15 phút
Pull request đã merge (30 ngày)
12

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PyCQA/docformatter

Tất cả issue của PyCQA/docformatter

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.