python / python/cpython

TabError and IndentationError from line continuation

オープン
#144,018 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

interpreter-core topic-parser type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

The documentation states:

Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation.

When this rule applies to some, but not all, lines in a block, a TabError is sometimes unexpectedly raised:

L1 = 'if 1:\n'
L2 = '    1\n'
L3 = '    \\\n'
L4 = '        1\n'
exec(L1 + L2 + L3 + L4)
# works as expected

L1 = 'if 1:\n'
L2 = '\t1\n'
L3 = '\t\\\n'
L4 = '\t\t1\n'
exec(L1 + L2 + L3 + L4)
# TabError: inconsistent use of tabs and spaces in indentation

Also, when a line containing only a backslash is explicitly joined with an indented line, an IndentationError is unexpectedly raised:

exec('\\\n    1')
# IndentationError: unexpected indent
CPython versions tested on:

3.10, 3.11, 3.12, 3.13, 3.14

Operating systems tested on:

macOS

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

まず、記載されている CPython バージョンで 2 つの exec() 再現コードを実行し、次に、両方のケースに関係するインデントと行継続の処理を追跡してください。報告された TabError と IndentationError の動作に対する回帰テストを追加し、関連のない他のインデントエラーを変更せずに、テストが意図した結果を捉えていることを確認してください。

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

評価

技術スタック
python
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

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

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