F704
(
ctx: &Ctx,
expr: &Expr,
kind: YieldOutsideFunctionKind,
)
| 1117 | |
| 1118 | /// F704 |
| 1119 | fn yield_outside_function<Ctx: SemanticSyntaxContext>( |
| 1120 | ctx: &Ctx, |
| 1121 | expr: &Expr, |
| 1122 | kind: YieldOutsideFunctionKind, |
| 1123 | ) { |
| 1124 | // We are intentionally not inspecting the async status of the scope for now to mimic F704. |
| 1125 | // await-outside-async is PLE1142 instead, so we'll end up emitting both syntax errors for |
| 1126 | // cases that trigger F704 |
| 1127 | |
| 1128 | if ctx.in_function_scope() { |
| 1129 | return; |
| 1130 | } |
| 1131 | |
| 1132 | if kind.is_await() { |
| 1133 | // `await` is allowed at the top level of a Jupyter notebook. |
| 1134 | // See: https://ipython.readthedocs.io/en/stable/interactive/autoawait.html. |
| 1135 | if ctx.in_module_scope() && ctx.in_notebook() { |
| 1136 | return; |
| 1137 | } |
| 1138 | if ctx.in_await_allowed_context() { |
| 1139 | return; |
| 1140 | } |
| 1141 | } else if ctx.in_yield_allowed_context() { |
| 1142 | return; |
| 1143 | } |
| 1144 | |
| 1145 | Self::add_error( |
| 1146 | ctx, |
| 1147 | SemanticSyntaxErrorKind::YieldOutsideFunction(kind), |
| 1148 | expr.range(), |
| 1149 | ); |
| 1150 | } |
| 1151 | |
| 1152 | /// Add a [`SemanticSyntaxErrorKind::ReboundComprehensionVariable`] if `expr` rebinds an |
| 1153 | /// iteration variable in `generators`. |
nothing calls this directly
no test coverage detected