Specialize syntax error for assignment expressions in invalid places
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Proposal:
There are a few places where (unparenthesized) assignment expressions are not accepted but users might think of using them. For example:
>>> func(arg=x := foo())
File "<python-input-0>", line 1
func(arg=x := foo())
^^
SyntaxError: invalid syntax
I find this error pretty confusing. It's not clear why this is a syntax error or what users should do it fix it (i.e. add parentheses).
I propose adding a specialized syntax error to point users in the right direction, similar to what's currently done for assert:
>>> assert x := 1
File "<python-input-12>", line 1
assert x := 1
^^^^^^
SyntaxError: cannot use named expression without parentheses here
Refs #138716, #146260
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず issue の例を再現し、assignment expressions に対する CPython の構文エラー処理を読み、assert に対して既存の専用診断と比較します。未かっこの無効な assignment expressions に、かっこの使用を促す明確なメッセージが表示され、有効な形式では既存の動作が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 58/100