Improve syntax error when brackets (parentheses) are mismatched

Đang mở
#98,278 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
compilers

Hướng nghiên cứu

Bắt đầu bằng cách xác định mã chẩn đoán của parser hoặc lỗi cú pháp xử lý các dấu ngoặc không khớp, sau đó tìm các kiểm thử hiện có cho những ví dụ được báo cáo. Cập nhật hành vi để chẩn đoán trỏ đến cả dấu ngoặc mở và dấu ngoặc đóng, đồng thời xác nhận các vị trí caret được hiển thị đối với các dấu ngoặc đơn trộn lẫn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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 '['
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.