F704
(
ctx: &Ctx,
expr: &Expr,
kind: YieldOutsideFunctionKind,
)
| 1065 | |
| 1066 | /// F704 |
| 1067 | fn yield_outside_function<Ctx: SemanticSyntaxContext>( |
| 1068 | ctx: &Ctx, |
| 1069 | expr: &Expr, |
| 1070 | kind: YieldOutsideFunctionKind, |
| 1071 | ) { |
| 1072 | // We are intentionally not inspecting the async status of the scope for now to mimic F704. |
| 1073 | // await-outside-async is PLE1142 instead, so we'll end up emitting both syntax errors for |
| 1074 | // cases that trigger F704 |
| 1075 | |
| 1076 | if ctx.in_function_scope() { |
| 1077 | return; |
| 1078 | } |
| 1079 | |
| 1080 | if kind.is_await() { |
| 1081 | // `await` is allowed at the top level of a Jupyter notebook. |
| 1082 | // See: https://ipython.readthedocs.io/en/stable/interactive/autoawait.html. |
| 1083 | if ctx.in_module_scope() && ctx.in_notebook() { |
| 1084 | return; |
| 1085 | } |
| 1086 | if ctx.in_await_allowed_context() { |
| 1087 | return; |
| 1088 | } |
| 1089 | } else if ctx.in_yield_allowed_context() { |
| 1090 | return; |
| 1091 | } |
| 1092 | |
| 1093 | Self::add_error( |
| 1094 | ctx, |
| 1095 | SemanticSyntaxErrorKind::YieldOutsideFunction(kind), |
| 1096 | expr.range(), |
| 1097 | ); |
| 1098 | } |
| 1099 | |
| 1100 | /// Add a [`SemanticSyntaxErrorKind::ReboundComprehensionVariable`] if `expr` rebinds an |
| 1101 | /// iteration variable in `generators`. |
nothing calls this directly
no test coverage detected