RustPython / RustPython/Parser
Illegal "yield (from)" python syntax accepted
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Rust
- Star
- 117
- Fork
- 38
- Merge trung bình
- 4 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 1
Mô tả
Originally reported as https://github.com/astral-sh/ruff/issues/4992.
I'm not quite sure where the incorrectness here is, but I think this bug indicates an incorrect parsing of the
yield fromexpression. The following is a python snippet with illegal syntax:def e(): x = yield from y = 5We can verify that it is indeed illegal syntax with:
$ python yield-elision.py File "/tmp/tmp.1z4PScoI6T/yield-elision.py", line 2 x = yield from y = 5 ^^^^^^^^^^^^ SyntaxError: assignment to yield expression not possibleRuff, however, believes this is valid syntax:
$ ruff yield-elision.py --show-source --show-fixes yield-elision.py:2:3: F841 [*] Local variable `x` is assigned to but never used | 2 | def e(): 3 | x = yield from y = 5 | ^ F841 | = help: Remove assignment to unused variable `x` yield-elision.py:2:18: F821 Undefined name `y` | 2 | def e(): 3 | x = yield from y = 5 | ^ F821 | Found 2 errors.And will attempt to fix it, leading to a self-reported parsing error:
$ ruff yield-elision.py --fix error: Autofix introduced a syntax error in `yield-elision.py` with rule codes F841: invalid syntax. Got unexpected token '=' at byte offset 24 --- def e(): yield from y = 5 --- yield-elision.py:2:3: F841 Local variable `x` is assigned to but never used yield-elision.py:2:18: F821 Undefined name `y` Found 2 errors.I believe this indicates a parsing bug.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ yield from trong issue và theo dõi cách parser xử lý biểu thức này. Công việc được xem là hoàn tất khi cú pháp Python không hợp lệ do Ruff báo cáo bị từ chối, thay vì được xử lý như mã hợp lệ hoặc tạo ra một autofix làm phát sinh lỗi cú pháp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python, rust
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100