From 21f6df59ed0c869657bf0aaf69935310fbe04243 Mon Sep 17 00:00:00 2001 From: Steven Troxler Date: Sat, 18 Dec 2021 10:55:56 -0800 Subject: [PATCH] PEP 677: Clarify support for PEP 646 Unpack/* (#2198) --- pep-0677.rst | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pep-0677.rst b/pep-0677.rst index 211b8a9de..44c22db98 100644 --- a/pep-0677.rst +++ b/pep-0677.rst @@ -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 -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: @@ -459,11 +460,21 @@ types by modifying the grammar for | '*' 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 --------------------------- - Precedence of -> ~~~~~~~~~~~~~~~~