Is there a way to be generic over the parameters of a generic type? #1634
-
For example, I want a method to accept a callable that takes a
For example, if it is given an argument
A practical application here is a deserializing hook: it is given a type (possibly a generic, like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Unfortunately no. First, something like |
Beta Was this translation helpful? Give feedback.
Unfortunately no. First, something like
Union[...]
isn't valid to pass to a function acceptingtype
- that only accepts actual classes. The solution to that is likely a new typing construct -TypeForm
. The PEP for that is still in draft stage though. SecondlyUnion[*Ts]
isn't supported itself. This was mentioned in early versions of the TypeVarTuple PEP, but was removed due to the limited number of use cases and implementation complexity required.