Skip to content

Commit b4c6fc7

Browse files
committed
improve comment and simplify phrasing of genexp grammar in the documentation
1 parent 0e68154 commit b4c6fc7

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

Doc/reference/expressions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Generator expressions
418418
A generator expression is a compact generator notation in parentheses:
419419

420420
.. productionlist:: python-grammar
421-
generator_expression: "(" (`expression` | "*" `or_expr`) `comp_for` ")"
421+
generator_expression: "(" `starred_expression` `comp_for` ")"
422422

423423
A generator expression yields a new generator object. Its syntax is the same as
424424
for comprehensions, except that it is enclosed in parentheses instead of

Python/codegen.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4522,7 +4522,6 @@ codegen_sync_comprehension_generator(compiler *c, location loc,
45224522
break;
45234523
case COMP_DICTCOMP:
45244524
if (val == NULL){
4525-
// dict unpacking case
45264525
VISIT(c, expr, elt);
45274526
ADDOP_I(c, elt_loc, DICT_UPDATE, depth+1);
45284527
}
@@ -4621,8 +4620,9 @@ codegen_async_comprehension_generator(compiler *c, location loc,
46214620
switch (type) {
46224621
case COMP_GENEXP:
46234622
if (elt->kind == Starred_kind){
4624-
// ADD_YIELD_FROM won't work here so we need an explicit loop
4625-
// this block is loosely based on codegen_for
4623+
/* ADD_YIELD_FROM won't work here like it does in the
4624+
synchronous case, so use an explicit loop to mimic the
4625+
bytecode for (z async for y in x for z in y). */
46264626
NEW_JUMP_TARGET_LABEL(c, async_unpack_start);
46274627
NEW_JUMP_TARGET_LABEL(c, async_unpack_end);
46284628
VISIT(c, expr, elt->v.Starred.value);
@@ -4664,7 +4664,6 @@ codegen_async_comprehension_generator(compiler *c, location loc,
46644664
break;
46654665
case COMP_DICTCOMP:
46664666
if (val == NULL){
4667-
// dict unpacking case
46684667
VISIT(c, expr, elt);
46694668
ADDOP_I(c, elt_loc, DICT_UPDATE, depth+1);
46704669
}

0 commit comments

Comments
 (0)