`--docstring-length` removes blank line after docstrings it doesn't format (ping-pong with ruff format / Black)
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Reproduce on a copy of the supplied example.py with docformatter --in-place --docstring-length 1 1 example.py, then compare the path taken with and without --docstring-length. The key is finding where the length-range check fails to gate the blank-line removal that happens after docstrings followed by a comment or nested def. Done means the example is unchanged and a regression test covers docstrings outside the configured range as well as ones that are reformatted.
索引モデルが issue の本文から書いたものです。
説明
Description
When --docstring-length is given, docformatter removes the blank line after a class or function docstring if the next line is a comment or a nested def. This happens even when the docstring is outside the configured length range, so docformatter does not format it. ruff format (and Black) put the blank line back, so the two tools undo each other on every run. Using both as pre-commit hooks therefore always fails.
This looks related to #350 and #354, but the fixes for those don't cover this case. It still reproduces on current master (c90b7eff34504dd2465b170d86d25f6007db89da).
Reproduction
example.py, already formatted by ruff format:
class Foo:
"""
Class docstring.
"""
# comment
x = 1
def outer():
"""
Function docstring.
"""
def inner():
pass
return inner
$ docformatter --in-place --docstring-length 1 1 example.py
Actual result
Both blank lines after the docstrings are removed, although neither docstring is 1 line long, so neither should be touched:
"""
Class docstring.
"""
-
# comment
x = 1
@@
"""
Function docstring.
"""
-
def inner():
pass
ruff format then adds them back:
$ ruff format --diff example.py
+
# comment
...
+
def inner():
Expected result
The file is unchanged. Docstrings outside the --docstring-length range shouldn't be modified, and neither should the code around them.
Notes
- Without
--docstring-length, the blank lines in this example are kept. It's the option alone that triggers this (--docstring-length 1 1on its own reproduces it). - A docstring that docformatter does reformat loses its following blank line in the same way. For example, with
--make-summary-multi-line,"""Short."""followed by a blank line and a# commentbecomes a multi-line docstring with no blank line after it. - Use case: we use
--make-summary-multi-line --docstring-length 1 1 --wrap-summaries 0only to turn one-line docstrings into multi-line ones, and leave everything else to ruff. As far as I know, docformatter is the only tool that supports this style. Ruff declined the inverse of D200 in astral-sh/ruff#4174.
Environment
- docformatter 1.7.8 (PyPI) and
master@ c90b7eff34504dd2465b170d86d25f6007db89da - ruff 0.13.1
- Python 3.13.7, Linux
This issue was drafted with the help of Claude Code, but the problem comes from the real needs of scikit-fingerprints, where we want docformatter's multi-line docstring style together with ruff format in pre-commit.
- 主要言語
- Python
- スター
- 600
- フォーク
- 107
- 平均マージ
- 22時間 15分
- マージ済み PR(30日)
- 12
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PyCQA/docformatter のほかの issue
-
fresh
難易度 3/5 1〜2日 初心者へのやさしさ 66/100
PyCQA/docformatter#414 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
docformatter fix does not consider parameters for added newlines再び着手できるかも @AtharvRG が 25 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンfresh
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
PyCQA/docformatter#408 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
BUG: Inconsistent behavior between `docformatter` and `black`再び着手できるかも @AtharvRG が 25 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンfresh
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
PyCQA/docformatter#399 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
1.7.8 crashes with a tokenize ValueError on a multi-line f-string inside parentheses再び着手できるかも @adityaanikam が 106 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンC: convention P: bug U: high
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
PyCQA/docformatter#367 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
1.7.8 rewrites the contents of a non-docstring triple-quoted string, silently changing its valueオープンC: convention P: bug U: high
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
PyCQA/docformatter#366 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
PyCQA/docformatter の issue をすべて見る
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
NatLabRockies/openstudio-mcp#286 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
intersystems/ipm#1338 ·
メンテナーはふだん 1 日以内に返信
-
separate_packages splits imports from the same explicitly configured package対応中かも @rahul05ranjan が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
The v0-through-v1 path derives ShutdownDuration its own way, silently overriding a user's definitionオープンv1
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信