Skip to content

Support special object.__new__ and object.__init__ in super. #794

Closed
@o11c

Description

@o11c

Currently, __new__ is not special at all. While full support is complicated, it is particularly irritating that object.__new__ cannot be added to stubs at all, since subclasses need to override it with different signatures and that is an error.

object.__new__ and object.__init__ are special in another way. For the object class itself, their signatures are (Subclass[T]) -> T and (T) -> None. However, when called from subclass constructors via super(), the signatures are (Subclass[T], *args, **kwargs) -> T and (T, *args, **kwargs) -> None.

In the above, T is a TypeVar that is bounded by the current class, and Subclass[T] is basically Intersection[type, Callable[..., T]] (i.e. supports duck typing once the Protocol stuff works).

(In my notes I am using use the term Class[T] to refer to Intersection[type, Callable[[signature of __init__], T]])

As an icky workaround, I tried using cast(Any, super()), but that says that super is not defined, before settling on # type: ignore

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions