RustPython / RustPython/Parser
Illegal "yield (from)" python syntax accepted
未关闭
还没有人认领这个 Issue。
bug
- 主要语言
- Rust
- 星标
- 117
- 派生
- 38
- 平均合并
- 4 天 7 小时
- 30 天内合并 PR
- 1
描述
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.
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先重现 issue 中的 yield from 示例,并跟踪 parser 如何处理该表达式。完成的标准是:Ruff 报告的无效 Python 语法会被拒绝,而不是被当作有效代码处理,或生成引入语法错误的 autofix。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python, rust
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100