Incorrect SyntaxError location for walrus operator in multi-line conditional expression
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
When using the walrus operator (:=) inside a multi-line conditional expression, Python raises a SyntaxError with the error position pointing to the wrong location.
The caret (^) is shown under the expression body instead of the if clause where the syntax issue actually occurs, making debugging misleading.
The error indicator should instead highlight the if portion (or walrus usage context), not the preceding expression line.
Code
(
1
if x := True
else 2
)
Traceback
File "[REDACTED]", line 2
1
^
SyntaxError: expected 'else' after 'if' expression
It locates error to 1 but it should have located to if x := True (line no. 3)
It does not errors when condition is parenthesized:
(
1
if (x := True)
else 2
) # output: 1
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-146305
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
CPython 3.14 で複数行の条件式とその括弧付きのバリエーションを再現し、続いて walrus 式の parser または構文エラー位置の処理を追跡します。括弧付きの場合は引き続き正しく解析されて結果を報告し、キャレットが if x := True の行を指すようになれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100