What is the Use Case for Using *args
as a Type Variable Tuple?
#1258
Unanswered
adam-grant-hendry
asked this question in
Q&A
Replies: 1 comment 10 replies
-
One use case is to pair it with a Though you might need to be type narrowing inside the function, the important thing is that it lets you then transfer those types to the return type in whatever way is appropriate. |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I don't understand the intended use case for
*args
as a Type Variable Tuple as laid out inPEP 646
.I don't understand why I wouldn't do what's recommended by typeshed and give
*args
the typeobject
so it can be any type and then type narrow in the function body. It seems like the target method that processes*args
is going to have to type narrow any way if its items are truly indeterminate in size and type.Maybe it is used for top-level functions that use helper functions that accept
*args
? ThePEP
providesos.execle
as an example, which passesargs
toos.execve
, buttypeshed
seems to manage with usingAny
(granted,TypeVarTuple
isn't supported bymypy
yet). Again though, I would have just typed this asobject
.What is the intended use case for
*args
as a Type Variable Tuple?Update
Please feel free to also review my SO answer related to typing
*args
and**kwargs
. I do not know when one should useTypeVarTuple
for*args
.Beta Was this translation helpful? Give feedback.
All reactions