ruff/crates/ruff_python_parser/resources
Brent Westbrook c2b2e42ad3
[syntax-errors] Invalid syntax in annotations (#17101)
Summary
--

This PR detects the use of invalid syntax in annotation scopes,
including
`yield` and `yield from` expressions and named expressions. I combined a
few
different types of CPython errors here, but I think the resulting error
messages
still make sense and are even preferable to what CPython gives. For
example, we
report `yield expression cannot be used in a type annotation` for both
of these:

```pycon
>>> def f[T](x: (yield 1)): ...
  File "<python-input-26>", line 1
    def f[T](x: (yield 1)): ...
                 ^^^^^^^
SyntaxError: yield expression cannot be used within the definition of a generic
>>> def foo() -> (yield x): ...
  File "<python-input-28>", line 1
    def foo() -> (yield x): ...
                  ^^^^^^^
SyntaxError: 'yield' outside function
```

Fixes https://github.com/astral-sh/ruff/issues/11118.

Test Plan
--

New inline tests, along with some updates to existing tests.
2025-04-03 17:56:55 -04:00
..
inline [syntax-errors] Invalid syntax in annotations (#17101) 2025-04-03 17:56:55 -04:00
invalid Consider 2-character EOL before line continuation (#12035) 2024-06-26 14:00:48 +05:30
valid [syntax-errors] Starred expressions in return, yield, and for (#17134) 2025-04-02 08:38:25 -04:00
.editorconfig Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30