1.7.8 rewrites the contents of a non-docstring triple-quoted string, silently changing its value
まだ誰も着手していません。
評価
調査の方向性
まず commit 926d9f0 と、括弧で囲まれた連結における三重引用符文字列の扱いを確認します。提供されている t.py の再現コードに docformatter --in-place を使用し、その後 Python で実行して X の結果の値を比較します。この非 docstring リテラルが変更されず、既存のフォーマット動作が引き続き機能すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
docformatter 1.7.8 treats a triple-quoted string that opens a parenthesized concatenation as a docstring and reformats its contents: it splits the first sentence off, indents the remainder by four spaces, and moves the closing quotes onto their own line. The file still compiles, so the only effect is that the string the program builds is wrong.
Reproducer
X = (
"""#!/bin/bash
# Ends here.
# A second line.
_real="""
+ "y"
)
$ docformatter --in-place t.py
$ python3 -c "ns={}; exec(open('t.py').read(), ns); print(repr(ns['X']))"
| version | value of X |
|---|---|
| 1.7.7 | '#!/bin/bash\n# Ends here.\n# A second line.\n_real=y' |
| 1.7.8 | '#!/bin/bash\n# Ends here.\n\n # A second line.\n _real=\n y' |
No config file and no flags are needed. The trigger is the string's position: the same literal assigned directly to a name is left alone.
# Ends here. matters because the trailing period is what makes docformatter treat the first line as a summary and split a description off after it.
Scale
Running 1.7.7 and 1.7.8 over the same 1,257-file tree, one file at a time, on CPython 3.11: of the 1,250 files both versions processed without error, 475 come out different. Most are docstring-formatting changes that look intentional, but this class is in there and is invisible: the output parses, so nothing downstream complains.
Root cause
git bisect between v1.7.7 and 1b3f03d names 926d9f0 ("refactor: split long functions into smaller functions", #318) as the first bad commit. Its parent fe1a85f is clean. Being a refactor, the behavior change looks unintended.
This is the same family as #344 (non-docstring literals in call arguments), but a different position: a parenthesized concatenation rather than a call argument, so #364 does not cover it. The reproducer above works as a test case.
Environment
CPython 3.11.15, Linux x86-64, docformatter==1.7.8 from PyPI. Still present on master.
- 主要言語
- Python
- スター
- 598
- フォーク
- 93
- 平均マージ
- 12日 10時間
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PyCQA/docformatter のほかの issue
-
fresh
難易度 3/5 1〜2日 初心者へのやさしさ 78/100
PyCQA/docformatter#385 ·
-
C: convention P: bug U: high
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
PyCQA/docformatter#367 · コメント 1 件 ·
-
fresh
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
PyCQA/docformatter#354 · リアクション 3 件 ·
-
C: stakeholder P: enhancement U: low
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
PyCQA/docformatter#346 ·
-
C: convention P: bug U: high
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
PyCQA/docformatter#345 · リアクション 1 件 ·
PyCQA/docformatter の issue をすべて見る
似ている issue
-
bug server
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sportsdataverse/sportsdataverse-py#641 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
googleapis/google-cloud-python#18532 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信