-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
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)) is RaisesGroup[ExceptionGroup[ValueError]].
Perhaps a code sample would make more sense:
from typing import Generic, TypeVar, overload
E = TypeVar("E", bound=BaseException)
E2 = TypeVar("E2", bound=BaseException)
class RaisesGroup(Generic[E]):
@overload
def __init__(self, a: type[E]):
...
@overload
def __init__(self: "RaisesGroup[BaseExceptionGroup[E2]]", a: "RaisesGroup[E2]"):
...
def __init__(self, a: object):
...
RaisesGroup(RaisesGroup(ValueError)) # currently: Argument 1 to "RaisesGroup" has incompatible type "RaisesGroup[ValueError]"; expected "RaisesGroup[Never]"Hnasar