Skip to content

Commit 62ddc5f

Browse files
rimi0108willingcrruuaanng
authored andcommitted
pythongh-125832: Clarify comment for inlined comprehensions as per PEP-709 (python#126322)
* Fix comprehensions comment to inlined by pep 709 * Update spacing Co-authored-by: RUANG (James Roy) <[email protected]> * Add reference to PEP 709 --------- Co-authored-by: Carol Willing <[email protected]> Co-authored-by: RUANG (James Roy) <[email protected]> (cherry picked from commit 868bfcc)
1 parent 2f77931 commit 62ddc5f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Python/compile.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5314,10 +5314,12 @@ compiler_call_helper(struct compiler *c, location loc,
53145314
return SUCCESS;
53155315
}
53165316

5317-
5318-
/* List and set comprehensions and generator expressions work by creating a
5319-
nested function to perform the actual iteration. This means that the
5320-
iteration variables don't leak into the current scope.
5317+
/* List and set comprehensions work by being inlined at the location where
5318+
they are defined. The isolation of iteration variables is provided by
5319+
pushing/popping clashing locals on the stack. Generator expressions work
5320+
by creating a nested function to perform the actual iteration.
5321+
This means that the iteration variables don't leak into the current scope.
5322+
See https://peps.python.org/pep-0709/ for additional information.
53215323
The defined function is called immediately following its definition, with the
53225324
result of that call being the result of the expression.
53235325
The LC/SC version returns the populated container, while the GE version is

0 commit comments

Comments
 (0)