For classes with both __new__ and __init__, when converting the constructor into a Callable, the spec says that
https://github.com/python/typing/blame/20096eeba502b1bf955fcf62b389adbaa63fc61b/docs/spec/constructors.rst#L457
class B:
""" __new__ and __init__ """
def __new__(cls, *args, **kwargs) -> Self:
...
def __init__(self, x: int) -> None:
...
reveal_type(accepts_callable(B)) # ``def (*args, **kwargs) -> B | def (x: int) -> B``
The conformance test says that
|
class Class3: |
|
"""__new__ and __init__""" |
|
|
|
def __new__(cls, *args, **kwargs) -> Self: |
|
raise NotImplementedError |
|
|
|
def __init__(self, x: int) -> None: ... |
|
|
|
|
|
r3 = accepts_callable(Class3) |
|
reveal_type(r3) # `def (x: int) -> Class3` |
For classes with both
__new__and__init__, when converting the constructor into a Callable, the spec says thathttps://github.com/python/typing/blame/20096eeba502b1bf955fcf62b389adbaa63fc61b/docs/spec/constructors.rst#L457
The conformance test says that
typing/conformance/tests/constructors_callable.py
Lines 54 to 64 in 20096ee