PEP 646 interesting case
I came across a case where I think PEP 646 would provide relief, but I don't know how to spell it. Suppose we have a class Property[T]: ``` class Property(Generic[T]): ... ``` Now we have a function tuples that takes several Property arguments with different type parameters and returns a Property whose type parameter is a Tuple: ``` def tuples(*possibilities: Possibility[?]) -> Possibility[?]: ``` The idea is that you call ``` p1: Possibility[int] p2: Possibility[str] p = tuples(p1, p2) reveal_type(p) # Possibility[Tuple[int, str]] ``` Somehow I can't figure out how we're supposed to write that with PEP 646. The best I can come up with is ``` def tuples(*possibilities: *Possibility[*Ts]) -> Possibility[Tuple[*Ts]]:` ``` but the first `*Ts` feels wrong -- it looks as if Possibility takes multiple type parameters, but that's not the case. Somehow my brain wants to use a loop construct, e.g. ``` def tuples(*possibilities: *Possibility[T] for T in Ts) -> Possibility[Tuple[*Ts]]: ``` Does anyone recall how this is supposed to be handled? Or was it put off till a later PEP? (That would be a shame, since this is the first variadic signature I've encountered in the wild in a long time.) PS. If you really want to know: https://github.com/DRMacIver/minithesis/pull/9 -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...
participants (5)
-
Caleb Donovick
-
Guido van Rossum
-
Matthew Rahtz
-
S Pradeep Kumar
-
Zac Hatfield Dodds