gh-131421: fix ASDL grammar for Dict to have an expr?* keys field (#131419)

In the `ast` documentation for Python:

* https://docs.python.org/3/library/ast.html#ast.Dict
it is made clear that:

> When doing dictionary unpacking using dictionary literals the expression to be expanded goes in the values list, with a `None` at the corresponding position in `keys`.

Hence, `keys` is really a `expr?*` and *not* a `expr*`.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Samuel 2025-05-05 00:03:38 +01:00 committed by GitHub
parent af5799f305
commit 30840706b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 30 deletions

4
Python/Python-ast.c generated
View file

@ -6362,7 +6362,7 @@ init_types(void *arg)
" | UnaryOp(unaryop op, expr operand)\n"
" | Lambda(arguments args, expr body)\n"
" | IfExp(expr test, expr body, expr orelse)\n"
" | Dict(expr* keys, expr* values)\n"
" | Dict(expr?* keys, expr* values)\n"
" | Set(expr* elts)\n"
" | ListComp(expr elt, comprehension* generators)\n"
" | SetComp(expr elt, comprehension* generators)\n"
@ -6419,7 +6419,7 @@ init_types(void *arg)
if (!state->IfExp_type) return -1;
state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
2,
"Dict(expr* keys, expr* values)");
"Dict(expr?* keys, expr* values)");
if (!state->Dict_type) return -1;
state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
"Set(expr* elts)");