-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Use self-type in __init__
to add extra generic types
#16752
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 fo 8000 r 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
__init__
to __init__
to add extra generic types
We should try to formally define the intended behavior for this construct. All of the major type checkers treat the If you would like to see this become part of the official typing spec, I encourage you to write a mini spec and post it in the python/typing forum for feedback. My sense is that this probably doesn't require a full PEP. If the spec is relatively straightforward and uncontroversial, it's something that the recently-formed Typing Council could ratify and incorporate into the typing spec. |
I'll see if I can express this in a formal manner, though I'm not sure I'm able to. For reference, this was a 1 line (... ok maybe technically +2-1) change in #16753 |
I've opened a (draft) issue on the |
This works in mypy nowadays (or at least my initial example does), as of #17348 Thanks @ilevkivskyi! It's possible there's other examples that don't work. I'm not sure. |
Feature
Allow using self-types to add intermediate generic types for
__init__
.Pitch
This would make python-trio/trio#2898 possible to type well without the awful hacks we had to do. Specifically making sure
RaisesGroup(RaisesGroup(ValueError))
isRaisesGroup[ExceptionGroup[ValueError]]
.Perhaps a code sample would make more sense:
The text was updated successfully, but these errors were encountered: