-
-
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
Type for classes expecting a certain generic parameter #7791
Comments
I don't fully understand the proposed use here, but I think you are proposing higher kinded types? Surprisingly we don't have an issue open for that. They are something I think we would like but are not on the roadmap for implementing currently. |
While I'm not very well acquainted with type theory lingo, I'm pretty sure what I describe above is indeed higher kindedness. Essentially what I'm trying to do is expect a class that is generic over some known type variable. As such I need the type over of such classes, which afaik is indeed what higher kindedness is is used for (currently mypy just gives an error that you cannot take the type of a class). The reason I want to do this is that I have two similar ABCs that are close enough that, in simple cases, one can write one can write an implementation that is compatible with both at the same time. The function (Of course the real code of of |
Also [I renamed |
This is mostly because there is already python/typing#548, I am however fine with having our own place for discussions. There are however two other (specific) feature requests that are closely related: #2354 and #6066 |
Closing as a duplicate of python/typing#548 |
Request Type: Feature Request
Mock-up repro (more detailed mock-up here):
Actual behaviour: There does seem to be any way in
mypy
to define a parameter as expecting “a class that is generic over some known TypeVar T”. Instead mypy lets me know that “Variable "typing.Generic" is not valid as a type” and at runtime “TypeError: typing.Generic[~AnyBase] is not valid as type argument” is raised.Expected behaviour: Some way to do this.
mypy version: 0.730
Python version: 3.7 (Debian)
mypy flags: None
It makes more sense when you see this in full as part of a cooperative multiple inheritance scheme involving #7790 and #7191… This example is indeed not very strongly motivated on its own, but it should work as nevertheless.
The text was updated successfully, but these errors were encountered: