-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Implement TypeVar(..., bound=<boundary_type>) #689
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
Comments
(Reid: we talked about you implementing this, you're probably a better match than I am for this.) |
Reid, please look at using |
This is almost done, but I ran into one tricky interaction with the way mypy handles the
This program is correctly accepted by current mypy, but with my implementation of For now I have just added a special case to allow any type variable to be instantiated with |
Using |
I noticed an inconsistency in the treatment of type variables with specific value restrictions like In any case, what should bounds on type variables of generic classes mean? At a minimum they become bounds on the types of the methods of the class, including the constructor(s); should it also be illegal to even write down the type |
The values should be restricted to the specified values in every context when using the form The type
|
Aha, I was fooled by one of the examples in the documentation, thinking it was instantiating a typevar to a subtype of one of the allowed types, when actually it was "implicitly upcasting" the arguments to the allowed type instead. An easy trap to fall into for a Haskell programmer :) I now agree that the behavior is consistent and as you describe. |
Now specified in PEP 484; see python/typing#59.
The text was updated successfully, but these errors were encountered: