Improve syntax error when brackets (parentheses) are mismatched

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
compilers

調査の方向性

まず、不一致の括弧を処理する parser または構文エラーの診断コードを見つけ、次に報告された例に対する既存のテストを探します。診断が開き括弧と閉じ括弧の両方を指すように動作を更新し、混在した括弧に対して表示されるキャレット位置を確認します。

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

説明

interpreter-core topic-parser type-feature

The syntax error for mismatched brackets uses a caret to point to the closing bracket. But sometimes it is the opening bracket which is wrong. We should point a caret at both.

For example, this simple expression points to the closing square bracket:

>>> obj{"some long expression"]
  File "<stdin>", line 1
    obj{"some long expression"]
                              ^
SyntaxError: closing parenthesis ']' does not match opening parenthesis '{'

But the real cause of the issue is the opening brace. It would be helpful to point at that as well:

    obj{"some long expression"]
       ^                      ^
SyntaxError: closing parenthesis ']' does not match opening parenthesis '{'

This is especially helpful in complex expressions with many mixed parentheses:

>>> obj[func(x[store[arg, a[i], b[j])])[y]]
  File "<stdin>", line 1
    obj[func(x[store[arg, a[i], b[j])])[y]]
                                    ^
SyntaxError: closing parenthesis ')' does not match opening parenthesis '['

The reader has to carefully match up brackets by hand to see where the opening bracket is. A second caret would make that instantaneous:

    obj[func(x[store[arg, a[i], b[j])])[y]]
                    ^               ^
SyntaxError: closing parenthesis ')' does not match opening parenthesis '['
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

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

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

はじめの一歩

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

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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