Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Indentation characters of the original code are not preserved

クローズ
#379 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
tooling

調査の方向性

まず _do_add_formatted_docstring と _do_add_unformatted_docstring から始め、次に _do_format_code とその tokenize.untokenize の使用箇所を調べます。提供されたタブインデントの再現コードを docformatter で実行し、docstring 内およびコードの継続行にあるタブがタブのまま維持され、なおかつフォーマットが正常に機能することを確認してください。

索引モデルが issue の本文から書いたものです。

説明

fresh

docformatter unnecessarily replaces tab characters with spaces. When a file
uses tabs, running docformatter on it changes indentation characters both
inside docstrings and in code outside the docstring.

Reproducer

def some_function(
	a_parameter
):
	"""Important documentation.

	with an indented item
	"""
	...
$ docformatter file.py
--- before/file.py
+++ after/file.py
@@ -1,8 +1,8 @@
 def some_function(
-	a_parameter
+ a_parameter
 ):
 	"""Important documentation.
 
-	with an indented item
-	"""
+ with an indented item
+ """
 	...

Cause

Two independent code paths substitute spaces for the original indentation
characters:

  1. _do_add_formatted_docstring and _do_add_unformatted_docstring build
    the indent for the docstring's internal lines as " " * token.start[1],
    based on the docstring's opening line. When the opening line is indented with
    a tab, each tab inside the docstring is replaced by a single space.

  2. _do_format_code runs the whole file through tokenize.untokenize,
    which reconstructs inter-token whitespace as " " * col_offset. This means
    that tabs on continuation lines are also replaced by a single space.

主要言語
Python
スター
598
フォーク
93
平均マージ
12日 10時間
マージ済み PR(30日)
1

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PyCQA/docformatter のほかの issue

PyCQA/docformatter の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。