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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I don't understand the intended use case for
*argsas 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
*argsthe typeobjectso it can be any type and then type narrow in the function body. It seems like the target method that processes*argsis 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? ThePEPprovidesos.execleas an example, which passesargstoos.execve, buttypeshedseems to manage with usingAny(granted,TypeVarTupleisn't supported bymypyyet). Again though, I would have just typed this asobject.What is the intended use case for
*argsas a Type Variable Tuple?Update
Please feel free to also review my SO answer related to typing
*argsand**kwargs. I do not know when one should useTypeVarTuplefor*args.Beta Was this translation helpful? Give feedback.
All reactions