RustPython / RustPython/Parser
Illegal "yield (from)" python syntax accepted
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 117
- Forks
- 38
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the yield from example from the issue and trace how the parser handles the expression. Done means Ruff's reported invalid Python syntax is rejected rather than treated as valid code or producing an autofix that introduces a syntax error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100