-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Self types in generic classes #2354
Comments
A motivating example is typeshed's AbstractSet:
With #2193 we can annotate
But, we don't have the tools to give |
I think this issue is resolved - we can talk about the generic part if the self type. Or maybe I don't completely understand the issue. |
What would the annotated version of AbstractSet's |
I admit all these underscores confuse me, but maybe you wanted something like this? class AS(Generic[_T_co]):
def __and__(self: AS[T1], s: AS[T2]) -> AS[T1]: ...
def __or__ (self: AS[T1], s: AS[T2]) -> AS[Union[T1, T2]]: ... |
(actually I think |
Those annotations aren't as specific as I'd like--I want to be able to use self types to select the right return type depending on the subclass of AbstractSet. So I'm imagining something like this, except that I don't think it's possible to write
|
|
@jboning Yes, that is what this issue was originally about. However, it's unclear if we'd want that annotation for
Arguably |
Huh. I agree that then it makes sense for MutableSet and FrozenSet to override with their own, more specific types for these methods. I'll go post a typeshed change for that. Is it still a useful example of the sort of annotation one might want to be able to write? |
Raising priority since there were quite a few requests for this recently. |
Decreasing priority back to normal since this seems like a somewhat complicated feature and requires an addition to |
Do something reasonable with self types (e.g.,
self: T
) in generic classes.This is continuation of work in #2193.
The text was updated successfully, but these errors were encountered: