I want to Bbe a subclass of some class A, and I want to override A.__new__ 1 . Typically, my code for this would have this basic structure:
class B(A):
def __new__(cls, ...):
ret = super(B, cls).__new__(cls, ...)
return ret
So type(B(...))really B. (Note: ellipses in super(B, cls).__new__(cls, ...)should not represent the same elements as ellipses in the signature B.__new__.)
But suppose now that I want to use the value returned by some factory method / function method A_Factory(which returns a type object A) as the initial value for the variable retin the constructor. If I just encoded this:
class B(A):
def __new__(cls, ...):
ret = A_Factory(...)
return ret
... then it type(B(...))will be A, not B.
ret B.__new__ , type(B(...)) B , , C of B, type(C(...)) C?
1 , __new__, , .