mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-121657: Display correct error message for yield from outside of a function (GH-121680)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
f4d6e45c1e
commit
178e44de8f
3 changed files with 8 additions and 1 deletions
|
@ -2247,6 +2247,11 @@ Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
SyntaxError: 'yield' outside function
|
SyntaxError: 'yield' outside function
|
||||||
|
|
||||||
|
>>> yield from [1,2]
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
SyntaxError: 'yield from' outside function
|
||||||
|
|
||||||
>>> def f(): x = yield = y
|
>>> def f(): x = yield = y
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Improve the :exc:`SyntaxError` message if the user tries to use
|
||||||
|
:keyword:`yield from <yield>` outside a function.
|
|
@ -6119,7 +6119,7 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
|
||||||
break;
|
break;
|
||||||
case YieldFrom_kind:
|
case YieldFrom_kind:
|
||||||
if (!_PyST_IsFunctionLike(SYMTABLE_ENTRY(c))) {
|
if (!_PyST_IsFunctionLike(SYMTABLE_ENTRY(c))) {
|
||||||
return compiler_error(c, loc, "'yield' outside function");
|
return compiler_error(c, loc, "'yield from' outside function");
|
||||||
}
|
}
|
||||||
if (c->u->u_scope_type == COMPILER_SCOPE_ASYNC_FUNCTION) {
|
if (c->u->u_scope_type == COMPILER_SCOPE_ASYNC_FUNCTION) {
|
||||||
return compiler_error(c, loc, "'yield from' inside async function");
|
return compiler_error(c, loc, "'yield from' inside async function");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue