-
Notifications
You must be signed in to change notification settings - Fork 268
Closed
Description
I propose allowing the use of @overload
on __new__
to specify the return type. E.g.:
T = TypeVar('T')
class MyClass(Generic[T]):
@overload
def __new__(cls,val: str) -> 'MyClass[int]':
pass
@overload
def __new__(cls,val: int) -> int:
pass
def __new__(cls,val):
if isinstance(val,int):
return val
r = super().__init__(cls)
if isinstance(val,str):
r.val = int(val)
r.val = val
return r
This is useful on its own, but if @overload
is allowed to have return types that only differ by the generic type argument (e.g. MyClass[int]
vs MyClass[str]
), then this would also supersede issue #307 and allow more complicated type argument deduction.
Metadata
Metadata
Assignees
Labels
No labels