F704
(
ctx: &Ctx,
expr: &Expr,
kind: YieldOutsideFunctionKind,
)
| 1166 | |
| 1167 | /// F704 |
| 1168 | fn yield_outside_function<Ctx: SemanticSyntaxContext>( |
| 1169 | ctx: &Ctx, |
| 1170 | expr: &Expr, |
| 1171 | kind: YieldOutsideFunctionKind, |
| 1172 | ) { |
| 1173 | // We are intentionally not inspecting the async status of the scope for now to mimic F704. |
| 1174 | // await-outside-async is PLE1142 instead, so we'll end up emitting both syntax errors for |
| 1175 | // cases that trigger F704 |
| 1176 | |
| 1177 | if ctx.in_function_scope() { |
| 1178 | return; |
| 1179 | } |
| 1180 | |
| 1181 | if kind.is_await() { |
| 1182 | // `await` is allowed at the top level of a Jupyter notebook. |
| 1183 | // See: https://ipython.readthedocs.io/en/stable/interactive/autoawait.html. |
| 1184 | if ctx.in_module_scope() && ctx.in_notebook() { |
| 1185 | return; |
| 1186 | } |
| 1187 | if ctx.in_await_allowed_context() { |
| 1188 | return; |
| 1189 | } |
| 1190 | } else if ctx.in_yield_allowed_context() { |
| 1191 | return; |
| 1192 | } |
| 1193 | |
| 1194 | Self::add_error( |
| 1195 | ctx, |
| 1196 | SemanticSyntaxErrorKind::YieldOutsideFunction(kind), |
| 1197 | expr.range(), |
| 1198 | ); |
| 1199 | } |
| 1200 | |
| 1201 | /// Add a [`SemanticSyntaxErrorKind::ReboundComprehensionVariable`] if `expr` rebinds an |
| 1202 | /// iteration variable in `generators`. |
nothing calls this directly
no test coverage detected