Skip to content

Replace "starred_list" with standard grammar term "expression_list" in for statement documentation #134026

Closed
@Yash-Vijay29

Description

@Yash-Vijay29

Documentation

In the compound statements docs, section 8.3 i found:

for_stmt ::= "for" target_list "in" starred_list ":" suite
["else" ":" suite]

However, starred_list does not appear to be a defined production rule elsewhere in the language reference. It seems to act more like a semantic placeholder to indicate that starred_expressions (like *x) are allowed in the iterable.

Since the real grammar uses expression_list — which already includes starred_expression — would it be more consistent and accurate to write this instead?:

for_stmt ::= "for" target_list "in" expression_list ":" suite
["else" ":" suite]

…and then note in the accompanying text that starred_expression is supported?
This might reduce confusion for readers trying to understand or implement the formal grammar.
Can I work on that?

Linked PRs

Activity

sanjai-11

sanjai-11 commented on May 15, 2025

@sanjai-11

Hi, I am willing to work on this issue #134026
Assign me to this issue.

Yash-Vijay29

Yash-Vijay29 commented on May 15, 2025

@Yash-Vijay29
ContributorAuthor

Hi, I am willing to work on this issue #134026 Assign me to this issue.

Hi, I actually opened this issue because I noticed the inconsistency and proposed the solution. I'm planning to submit a PR for it shortly. Appreciate the interest, but I’ll be taking this one. I asked in the issues because even i am not sure if its supposed to be changed or whether "starred_list" is correct. Im hoping for someone more experienced to help clarify it. I am new here too and this is my first doc inconsistency, I do not have the power to assign issues as thats only for trusted developers i believe

sanjai-11

sanjai-11 commented on May 15, 2025

@sanjai-11

Got it, Thanks

skirpichev

skirpichev commented on May 15, 2025

@skirpichev
Contributor

See

cpython/Grammar/python.gram

Lines 715 to 723 in 6df3976

star_expressions[expr_ty]:
| a=star_expression b=(',' c=star_expression { c })+ [','] {
_PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) }
| a=star_expression ',' { _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) }
| star_expression
star_expression[expr_ty] (memo):
| '*' a=bitwise_or { _PyAST_Starred(a, Load, EXTRA) }
| expression

Yash-Vijay29

Yash-Vijay29 commented on May 15, 2025

@Yash-Vijay29
ContributorAuthor

ah okay. Sorry to bother i must have missed it as i hit "starred" on my ctrl+f in the grammar. Thank you

skirpichev

skirpichev commented on May 15, 2025

@skirpichev
Contributor

No, you misunderstood. This is a quote from the grammar for your reference. I believe issue is valid.

Yash-Vijay29

Yash-Vijay29 commented on May 15, 2025

@Yash-Vijay29
ContributorAuthor

No, you misunderstood. This is a quote from the grammar for your reference. I believe issue is valid.

oh okay.. its my first issue ever on github so am a bit nervous.
so i change the starred_list into star_expression?

skirpichev

skirpichev commented on May 15, 2025

@skirpichev
Contributor

so i change the starred_list into star_expression?

I'm not sure about naming. But whatever it will be, you should define the starred_list.

Yash-Vijay29

Yash-Vijay29 commented on May 15, 2025

@Yash-Vijay29
ContributorAuthor

Oh okay. I will look into doing that

6 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Replace "starred_list" with standard grammar term "expression_list" in for statement documentation · Issue #134026 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant