Brent Westbrook
acc5662e8b
[syntax-errors] Allow yield in base classes and annotations ( #17206 )
...
Summary
--
This PR fixes the issue pointed out by @JelleZijlstra in
https://github.com/astral-sh/ruff/pull/17101#issuecomment-2777480204 .
Namely, I conflated two very different errors from CPython:
```pycon
>>> def m[T](x: (yield from 1)): ...
File "<python-input-310>", line 1
def m[T](x: (yield from 1)): ...
^^^^^^^^^^^^
SyntaxError: yield expression cannot be used within the definition of a generic
>>> def m(x: (yield from 1)): ...
File "<python-input-311>", line 1
def m(x: (yield from 1)): ...
^^^^^^^^^^^^
SyntaxError: 'yield from' outside function
>>> def outer():
... def m(x: (yield from 1)): ...
...
>>>
```
I thought the second error was the same as the first, but `yield` (and
`yield from`) is actually valid in this position when inside a function
scope. The same is true for base classes, as pointed out in the original
comment.
We don't currently raise an error for `yield` outside of a function, but
that should be handled separately.
On the upside, this had the benefit of removing the
`InvalidExpressionPosition::BaseClass` variant and the
`allow_named_expr` field from the visitor because they were both no
longer used.
Test Plan
--
Updated inline tests.
2025-04-04 13:48:28 -04:00
..
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-07-22 14:44:20 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-06-03 18:23:50 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-19 16:46:15 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-05 13:19:09 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-06-17 06:47:00 +00:00
2024-06-17 06:47:00 +00:00
2024-06-17 06:47:00 +00:00
2024-06-17 06:47:00 +00:00
2024-04-18 17:57:39 +05:30
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-17 11:17:27 +00:00
2025-03-17 11:17:27 +00:00
2025-03-05 17:08:18 +00:00
2025-03-17 11:17:27 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-05 17:08:18 +00:00
2025-03-17 11:17:27 +00:00
2024-04-18 17:57:39 +05:30
2025-03-29 12:07:20 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-03 17:55:37 -04:00
2025-04-03 17:55:37 -04:00
2025-03-21 15:06:22 -04:00
2025-03-04 16:50:09 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-13 15:55:17 -04:00
2024-04-18 17:57:39 +05:30
2024-04-23 04:19:05 +00:00
2024-04-23 04:19:05 +00:00
2024-04-23 04:19:05 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-05 13:19:09 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-04 13:48:28 -04:00
2025-04-04 13:48:28 -04:00
2025-04-04 13:48:28 -04:00
2025-04-03 17:56:55 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-26 12:27:16 -04:00
2025-03-06 11:57:20 -05:00
2025-03-06 11:57:20 -05:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-02-27 10:23:15 -05:00
2024-06-03 18:23:50 +05:30
2024-06-03 18:23:50 +05:30
2024-06-03 18:23:50 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-06-03 18:23:50 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-03 17:32:39 -04:00
2024-04-18 17:57:39 +05:30
2025-03-14 15:06:42 -04:00
2025-03-14 15:06:42 -04:00
2024-04-19 11:36:26 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-14 15:20:44 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-17 08:54:55 -04:00
2025-03-06 12:18:13 -05:00
2025-03-18 11:12:15 -04:00
2025-03-05 13:46:43 +00:00
2024-12-19 13:36:32 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-21 14:45:25 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-02 08:38:25 -04:00
2025-04-02 08:38:25 -04:00
2025-04-02 08:38:25 -04:00
2025-03-29 12:35:47 -04:00
2025-03-14 14:51:34 +00:00
2025-03-14 14:51:34 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-12-10 17:50:55 -06:00
2025-03-17 08:54:55 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-04 16:53:38 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-26 09:47:29 +02:00
2024-04-26 09:47:29 +02:00
2024-04-26 09:47:29 +02:00
2024-04-26 09:47:29 +02:00
2024-04-18 17:57:39 +05:30
2024-04-26 09:47:29 +02:00
2024-04-26 09:47:29 +02:00
2024-06-26 08:10:35 +05:30
2025-03-04 17:20:10 +00:00
2025-03-14 15:06:42 -04:00
2025-03-14 15:06:42 -04:00
2025-03-14 15:06:42 -04:00
2024-04-18 17:57:39 +05:30
2025-02-28 17:13:46 -05:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-06-06 08:59:56 +00:00
2024-04-18 17:57:39 +05:30
2025-03-29 12:07:20 -04:00