Commit acc5662
authored
[syntax-errors] Allow
Summary
--
This PR fixes the issue pointed out by @JelleZijlstra in
#17101 (comment).
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.yield in base classes and annotations (#17206)1 parent 33a56f1 commit acc5662
16 files changed
Lines changed: 1074 additions & 679 deletions
File tree
- crates
- ruff_linter/src/checkers/ast
- ruff_python_parser
- resources/inline
- err
- ok
- src
- tests
- snapshots
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
590 | 594 | | |
591 | 595 | | |
592 | 596 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
| |||
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | | - | |
7 | 5 | | |
8 | | - | |
9 | 6 | | |
10 | | - | |
11 | 7 | | |
12 | 8 | | |
13 | 9 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
131 | 146 | | |
132 | 147 | | |
133 | 148 | | |
134 | 149 | | |
135 | 150 | | |
136 | | - | |
137 | 151 | | |
138 | | - | |
139 | 152 | | |
140 | | - | |
141 | 153 | | |
142 | | - | |
143 | 154 | | |
144 | 155 | | |
145 | 156 | | |
| |||
148 | 159 | | |
149 | 160 | | |
150 | 161 | | |
151 | | - | |
152 | 162 | | |
153 | | - | |
154 | 163 | | |
155 | 164 | | |
156 | 165 | | |
157 | 166 | | |
158 | 167 | | |
159 | 168 | | |
160 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
161 | 173 | | |
162 | 174 | | |
163 | | - | |
| 175 | + | |
164 | 176 | | |
165 | 177 | | |
166 | 178 | | |
| |||
173 | 185 | | |
174 | 186 | | |
175 | 187 | | |
176 | | - | |
| 188 | + | |
177 | 189 | | |
178 | 190 | | |
179 | 191 | | |
180 | 192 | | |
181 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
182 | 197 | | |
183 | 198 | | |
184 | 199 | | |
185 | | - | |
186 | | - | |
187 | 200 | | |
188 | 201 | | |
189 | 202 | | |
190 | 203 | | |
191 | | - | |
192 | 204 | | |
193 | | - | |
194 | 205 | | |
195 | 206 | | |
196 | 207 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 208 | + | |
205 | 209 | | |
| 210 | + | |
206 | 211 | | |
207 | 212 | | |
208 | 213 | | |
| |||
217 | 222 | | |
218 | 223 | | |
219 | 224 | | |
220 | | - | |
221 | 225 | | |
222 | 226 | | |
223 | 227 | | |
| |||
625 | 629 | | |
626 | 630 | | |
627 | 631 | | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | 632 | | |
635 | 633 | | |
636 | 634 | | |
| |||
858 | 856 | | |
859 | 857 | | |
860 | 858 | | |
861 | | - | |
862 | 859 | | |
863 | 860 | | |
864 | 861 | | |
| |||
872 | 869 | | |
873 | 870 | | |
874 | 871 | | |
875 | | - | |
876 | 872 | | |
877 | 873 | | |
878 | 874 | | |
| |||
1086 | 1082 | | |
1087 | 1083 | | |
1088 | 1084 | | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | 1085 | | |
1100 | 1086 | | |
1101 | 1087 | | |
| |||
1108 | 1094 | | |
1109 | 1095 | | |
1110 | 1096 | | |
1111 | | - | |
| 1097 | + | |
1112 | 1098 | | |
1113 | 1099 | | |
1114 | 1100 | | |
| |||
1166 | 1152 | | |
1167 | 1153 | | |
1168 | 1154 | | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
1169 | 1158 | | |
1170 | 1159 | | |
1171 | 1160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
493 | 497 | | |
494 | 498 | | |
495 | 499 | | |
| |||
Lines changed: 0 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
0 commit comments