From 62ddc5fb65fa22f1b76390ec17abbf15b680ff08 Mon Sep 17 00:00:00 2001 From: rimchoi Date: Sun, 3 Nov 2024 02:04:53 +0900 Subject: [PATCH] gh-125832: Clarify comment for inlined comprehensions as per PEP-709 (#126322) * Fix comprehensions comment to inlined by pep 709 * Update spacing Co-authored-by: RUANG (James Roy) * Add reference to PEP 709 --------- Co-authored-by: Carol Willing Co-authored-by: RUANG (James Roy) (cherry picked from commit 868bfcc02ed42a1042851830b79c6877b7f1c7a8) --- Python/compile.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Python/compile.c b/Python/compile.c index d5c42ce3e3490b..ccb3bd526bbb49 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -5314,10 +5314,12 @@ compiler_call_helper(struct compiler *c, location loc, return SUCCESS; } - -/* List and set comprehensions and generator expressions work by creating a - nested function to perform the actual iteration. This means that the - iteration variables don't leak into the current scope. +/* List and set comprehensions work by being inlined at the location where + they are defined. The isolation of iteration variables is provided by + pushing/popping clashing locals on the stack. Generator expressions work + by creating a nested function to perform the actual iteration. + This means that the iteration variables don't leak into the current scope. + See https://peps.python.org/pep-0709/ for additional information. The defined function is called immediately following its definition, with the result of that call being the result of the expression. The LC/SC version returns the populated container, while the GE version is