From cbfd92a22e0bbbc96191d768edb48ec9fe1956a1 Mon Sep 17 00:00:00 2001 From: Gregor Ziegltrum Date: Sat, 13 Jul 2024 12:48:26 +0200 Subject: [PATCH 1/3] gh-121657: Display correct error message for yield from outside of a function --- Lib/test/test_generators.py | 5 +++++ Python/compile.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index daa65718bfc905..34f79dafbe9851 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -2247,6 +2247,11 @@ def printsolution(self, x): ... SyntaxError: 'yield' outside function +>>> yield from [1,2] +Traceback (most recent call last): + ... +SyntaxError: 'yield from' outside function + >>> def f(): x = yield = y Traceback (most recent call last): ... diff --git a/Python/compile.c b/Python/compile.c index 4190b141324b38..ca64b5cd376521 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -6119,7 +6119,7 @@ compiler_visit_expr(struct compiler *c, expr_ty e) break; case YieldFrom_kind: 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) { return compiler_error(c, loc, "'yield from' inside async function"); From 0895368c3994d4b9df6411cb52ad15a5552619f7 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 13 Jul 2024 12:27:33 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst b/Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst new file mode 100644 index 00000000000000..0c471f2cdecc7e --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst @@ -0,0 +1 @@ +Show the correct ``SyntaxError`` if the user tries to use ``yield from`` outside a function From 5ea0d5f48baad692ae3afc33d0b346adeea780a0 Mon Sep 17 00:00:00 2001 From: Gregor <36135323+gege-hoho@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:37:54 +0200 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- .../2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst b/Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst index 0c471f2cdecc7e..cb18629d79f5ce 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-07-13-12-27-31.gh-issue-121657.wgOYLw.rst @@ -1 +1,2 @@ -Show the correct ``SyntaxError`` if the user tries to use ``yield from`` outside a function +Improve the :exc:`SyntaxError` message if the user tries to use +:keyword:`yield from ` outside a function.