You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Except for the special case where the implementation for one or the other is inherited from object. In that case the signature of the one that's overridden prevails.
class A:
def __init__(self, x: int) -> None:
pass
class B(A):
def __new__(cls) -> 'B':
return object.__new__(cls)
B()
even though it crashes at runtime.
Per #5642 (review):
The rule CPython uses is this (for a class C with superclass B, where B is not object):
If both C.__new__ and C.__init__ refer to their versions in object, the signature is def () -> C.
If exactly one of C.__new__ and C.__object__ refers to its object version, the other determines the signature.
If both override their corresponding object versions, they must match -- even if they don't come from the same class (say, if one comes from C and the other from B).
Activity
JukkaL commentedon Nov 29, 2015
This is follow-up to #982.
gvanrossum commentedon Nov 29, 2015
Except for the special case where the implementation for one or the other is inherited from
object. In that case the signature of the one that's overridden prevails.msullivan commentedon Sep 19, 2018
A test case
even though it crashes at runtime.
Per #5642 (review):
The rule CPython uses is this (for a class
Cwith superclassB, whereBis notobject):C.__new__andC.__init__refer to their versions inobject, the signature isdef () -> C.C.__new__andC.__object__refers to itsobjectversion, the other determines the signature.objectversions, they must match -- even if they don't come from the same class (say, if one comes fromCand the other fromB).