Commit 73d2c0a
committed
[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, the
`InvalidExpressionPosition::TypeAnnotation` variant, and the `allow_named_expr`
field from the visitor because they were all no longer used.
Test Plan
--
Updated inline tests.yield in base classes and annotations1 parent 5cee346 commit 73d2c0a
File tree
12 files changed
+611
-690
lines changed- crates/ruff_python_parser
- resources/inline
- err
- ok
- src
- tests/snapshots
12 files changed
+611
-690
lines changedLines 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: 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 | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
131 | 136 | | |
132 | 137 | | |
133 | 138 | | |
134 | 139 | | |
135 | 140 | | |
136 | | - | |
137 | 141 | | |
138 | | - | |
139 | 142 | | |
140 | | - | |
141 | 143 | | |
142 | | - | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
151 | | - | |
152 | 152 | | |
153 | | - | |
154 | | - | |
| 153 | + | |
155 | 154 | | |
156 | 155 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 156 | + | |
165 | 157 | | |
166 | 158 | | |
167 | 159 | | |
| |||
173 | 165 | | |
174 | 166 | | |
175 | 167 | | |
176 | | - | |
| 168 | + | |
177 | 169 | | |
178 | 170 | | |
179 | 171 | | |
180 | 172 | | |
181 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
182 | 177 | | |
183 | 178 | | |
184 | 179 | | |
185 | | - | |
186 | | - | |
187 | 180 | | |
188 | 181 | | |
189 | 182 | | |
190 | 183 | | |
191 | | - | |
192 | 184 | | |
193 | | - | |
194 | | - | |
| 185 | + | |
195 | 186 | | |
196 | 187 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 188 | + | |
205 | 189 | | |
| 190 | + | |
206 | 191 | | |
207 | 192 | | |
208 | 193 | | |
| |||
217 | 202 | | |
218 | 203 | | |
219 | 204 | | |
220 | | - | |
221 | 205 | | |
222 | 206 | | |
223 | 207 | | |
| |||
625 | 609 | | |
626 | 610 | | |
627 | 611 | | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | 612 | | |
635 | 613 | | |
636 | 614 | | |
| |||
857 | 835 | | |
858 | 836 | | |
859 | 837 | | |
860 | | - | |
861 | | - | |
862 | 838 | | |
863 | 839 | | |
864 | 840 | | |
| |||
870 | 846 | | |
871 | 847 | | |
872 | 848 | | |
873 | | - | |
874 | 849 | | |
875 | | - | |
876 | 850 | | |
877 | 851 | | |
878 | 852 | | |
| |||
1086 | 1060 | | |
1087 | 1061 | | |
1088 | 1062 | | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | 1063 | | |
1100 | 1064 | | |
1101 | 1065 | | |
| |||
1108 | 1072 | | |
1109 | 1073 | | |
1110 | 1074 | | |
1111 | | - | |
| 1075 | + | |
1112 | 1076 | | |
1113 | 1077 | | |
1114 | 1078 | | |
| |||
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