PEP 677: Clarify support for PEP 646 Unpack/* (#2198)

This commit is contained in:
Steven Troxler 2021-12-18 10:55:56 -08:00 committed by GitHub
parent 80e009085f
commit 21f6df59ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -450,7 +450,8 @@ Here are our proposed changes to the `Python Grammar
If PEP 646 is accepted, we intend to include support for unpacked If PEP 646 is accepted, we intend to include support for unpacked
types by modifying the grammar for types in two ways. To support the "star-for-unpack" syntax proposed in
PEP 646, we will modify the grammar for
``callable_type_positional_argument`` as follows:: ``callable_type_positional_argument`` as follows::
callable_type_positional_argument: callable_type_positional_argument:
@ -459,11 +460,21 @@ types by modifying the grammar for
| '*' expression ',' | '*' expression ','
| '*' expression &')' | '*' expression &')'
With this change, a type of the form ``(int, *Ts) -> bool`` should
evaluate the AST form::
CallableType(
ArgumentsList(Name("int"), Starred(Name("Ts")),
Name("bool")
)
and be treated by type checkers as equivalent to
``Callable[[int, Unpack[Ts]], bool]``.
Implications of the Grammar Implications of the Grammar
--------------------------- ---------------------------
Precedence of -> Precedence of ->
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~