On Fri, Jan 29, 2021 at 2:28 AM Stefano Borini <stefano.borini@gmail.com> wrote:
On Tue, 19 Jan 2021 at 13:51, <gohanpra@gmail.com> wrote:
> Hello,
> This is a great PEP. It turns out to be applicable in a variety of scenarios.
> Case in point: Matthew Rahtz and I are working on PEP 646: Variadic Generics (https://www.python.org/dev/peps/pep-0646/; discussion on typing-sig). It is a type system feature that allows specifying an arbitrary tuple of type variables instead of a single type variable.
> We plan to use your proposed syntax to represent unpacking a tuple type. This would be analogous to `*` for unpacking a tuple value:
> + `Tensor[int, *Ts, str]` and `Tensor[*Ts1, *Ts2]`
> + such variadic classes would be declared as `class Tensor(Generic[T, *Ts, T2]):`
> Questions:
> 1. Does PEP 637 support unpacking multiple `*` arguments?
>    - e.g., Tensor[int, *Ts, str, *Ts2]

Yes, technically yes, and it does in our experimental branch.


Brandt and I are unsure about the semantics of it, specifically the
corner case of star unpacking a tuple with one element. The current
PEP says that the following two are equivalent:

a[1] and a[*(1,)]. (calls __getitem__ with index = 1)

However, the way it's implemented now, these two are equivalent

a[1,] and a[*(1,)] (calls __getitem__ with index = (1,))

I think we would both love a discussion over it.

I think for PEP 646 it doesn't matter. That PEP is mostly concerned with static checks and the static checker can assign this any meaning it wants as long as it is syntactically allowed.

Honestly I think it's fine the way you have implemented it -- since there is a difference between a[1] and a[1,], a[*t] where len(t) == 1 has to make a choice, and it's fine if this always passes a tuple.
> 2. Does PEP 637 allow a positional argument after a `*`?
>    - e.g., Generic[T, *Ts, T2]



--Guido van Rossum (python.org/~guido)