Skip to content

Conversation

@miss-islington
Copy link
Contributor

@miss-islingtonmiss-islington commented Sep 26, 2024

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 ,.

(cherry picked from commit 7d3497f)

Co-authored-by: Matthew Rahtz [email protected]
Co-authored-by: Jelle Zijlstra [email protected]


📚 Documentation preview 📚: https://cpython-previews--124632.org.readthedocs.build/

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 ,`. (cherry picked from commit 7d3497f) Co-authored-by: Matthew Rahtz <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
@Yhg1sYhg1s merged commit 410e0ef into python:3.13Sep 26, 2024
@miss-islingtonmiss-islington deleted the backport-7d3497f-3.13 branch January 2, 2026 16:54
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docsDocumentation in the Doc dirskip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@miss-islington@JelleZijlstra@Yhg1s@mrahtz