ruff/crates/ruff_python_parser/tests
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
..
snapshots [syntax-errors] Invalid syntax in annotations (#17101) 2025-04-03 17:56:55 -04:00
fixtures.rs [syntax-errors] Detect duplicate keys in match mapping patterns (#17129) 2025-04-03 10:22:37 -04:00
generate_inline_tests.rs [syntax-errors] Start detecting compile-time syntax errors (#16106) 2025-03-21 14:45:25 -04:00