Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/spec/constructors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ constructor calls:
2. If the class defines a ``__new__`` method or inherits a ``__new__`` method
from a base class other than ``object``, a type checker should synthesize a
callable from the parameters and return type of that method after it is bound
to the class.
to the class. If the ``__new__`` method's only non-``cls`` parameters are

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this the right behavior? Also shouldn't there be requirements on the type annotations for the args/kwargs parameters?

``*args`` and ``**kwargs`` (i.e. a passthrough), the method is considered
to not constrain the constructor signature, and this step produces no
callable type.

3. If the return type of the method in step 2 evaluates to a type that is not a
subclass of the class being constructed (or a union that includes such a
Expand Down Expand Up @@ -454,7 +457,7 @@ constructor calls:


reveal_type(accepts_callable(A)) # ``def () -> A``
reveal_type(accepts_callable(B)) # ``def (*args, **kwargs) -> B | def (x: int) -> B``
reveal_type(accepts_callable(B)) # ``def (x: int) -> B``
reveal_type(accepts_callable(C)) # ``def (x: int) -> int``
reveal_type(accepts_callable(D)) # ``def () -> NoReturn``
reveal_type(accepts_callable(E)) # ``def () -> A``
Expand Down