-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parametric type aliases #568
Comments
Hm, in an earlier version of the code I have in typehinting/prototyping I tried this, and I ended up not liking the complexity (of the implementation, and of the semantics). I don't think the PEP prescribes this behavior. |
I now recall where I got in trouble. It seems reasonable to have parameters that are themselves complex, e.g.:
This cannot be parameterized further. But this can:
and then it would seem reasonable to define the following as equivalent as the first definition above:
We could even have something like this:
and assume that
This may all be easy enough for mypy, but supporting this at runtime and figuring out exactly how many parameters In the end I think there's not enough use to require all this complexity. |
@gvanrossum This is why C++ makes you specify template argument order separately: template <typename A, typename B>
using MyType = MyOtherType<int, B, char, A>; What if an explicit type used for this? For instance, you last example would be written as: MyType = ParameterizedType[T, U][Dict[Union[T, U], Union[U, T]]] Also, ParameterizedType could use PEP 472 for defaults ( As for runtime issues, ParameterizedType could determine everything when it is instantiated (maybe lambdas could be used). |
Okay, marking this as an enhancement proposal for now. If there isn't enough interest (and PEP 484 does not include anything of the like) then I'll probably close this at some point. |
Looks like a duplicate of #606 |
Agreed, closing this one as it's the shorter one (though not by much). |
It should be possible to define type aliases that take type parameters by having free type variables in the alias initializer. For example, this should be valid:
Another example:
For this to work generally,
List[x]
,Union[...]
, etc. must be indexable at runtime (this is related to #530 and #556 -- these should be implemented before this issue).The text was updated successfully, but these errors were encountered: