Skip to content

gh-115528: Update language reference for PEP 646 - #120294

Closed
mrahtz wants to merge 4 commits into
python:mainfrom
mrahtz:docs
Closed

gh-115528: Update language reference for PEP 646#120294
mrahtz wants to merge 4 commits into
python:mainfrom
mrahtz:docs

Conversation

@bedevere-appbedevere-appBot added docs Documentation in the Doc dir skip news labels Jun 9, 2024
@mrahtz
mrahtz marked this pull request as ready for review June 9, 2024 17:55
Comment threadDoc/reference/compound_stmts.rst Outdated
Comment threadDoc/reference/expressions.rst Outdated

.. productionlist:: python-grammar
expression_list: `expression` ("," `expression`)* [","]
expression_list: `starred_expression` ("," `starred_expression`)* [","]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not strictly correct. expression_list according to the grammar is what appears after yield, but def f(): yield *a is a SyntaxError. (However, yield a, *b is legal.)

mrahtz added 4 commits June 30, 2024 12:01
To recap: the objective is to make starred expressions valid in `subscription`,
which is used for generics: `Generic[...]`, `list[...]`, etc.
What _is_ gramatically valid in such contexts? Seemingly any of the following.
(At least, none of the following throw `SyntaxError` in a 3.12.3 REPL.)
Generic[x]
Generic[*x]
Generic[*x, y]
Generic[y, *x]
Generic[x := 1]
Generic[x := 1, y := 2]
So introducting
flexible_expression: expression | assignment_expression | starred_item
end then switching `subscription` to use `flexible_expression` sorts that.
But then we need to field `yield` - for which any of the following are
apparently valid:
yield x
yield x,
yield x, y
yield *x,
yield *x, *y
Introducing a separate `yield_list` is the simplest way I've been figure out to
do this - separating out the special case of `starred_item ,`.
@ghost

ghost commented Jun 30, 2024

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@mrahtz

Copy link
Copy Markdown
ContributorAuthor

Ugh sorry for the spam all - Git mistake. Let me start a fresh PR.

@mrahtzmrahtz closed this Jun 30, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewdocsDocumentation in the Doc dirskip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@mrahtz@JelleZijlstra@AlexWaygood