Skip to content

Commit 5e9ec10

Browse files
committed
only allow await in notebooks, not all three kinds
1 parent 3cc131b commit 5e9ec10

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

crates/ruff_python_parser/src/semantic_errors.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -682,23 +682,27 @@ impl SemanticSyntaxChecker {
682682
expr: &Expr,
683683
kind: YieldOutsideFunctionKind,
684684
) {
685-
if !self.in_function_scope && !self.source_type.is_ipynb() {
686-
// test_err yield_outside_function
687-
// yield 1
688-
// yield from 1
689-
// await 1
690-
691-
// test_ok yield_inside_function
692-
// def f():
693-
// yield 1
694-
// yield from 1
695-
// await 1
696-
Self::add_error(
697-
ctx,
698-
SemanticSyntaxErrorKind::YieldOutsideFunction(kind),
699-
expr.range(),
700-
);
685+
if self.in_function_scope {
686+
return;
687+
}
688+
if self.source_type.is_ipynb() && matches!(kind, YieldOutsideFunctionKind::Await) {
689+
return;
701690
}
691+
// test_err yield_outside_function
692+
// yield 1
693+
// yield from 1
694+
// await 1
695+
696+
// test_ok yield_inside_function
697+
// def f():
698+
// yield 1
699+
// yield from 1
700+
// await 1
701+
Self::add_error(
702+
ctx,
703+
SemanticSyntaxErrorKind::YieldOutsideFunction(kind),
704+
expr.range(),
705+
);
702706
}
703707

704708
/// Add a [`SyntaxErrorKind::ReboundComprehensionVariable`] if `expr` rebinds an iteration

0 commit comments

Comments
 (0)