Let's assume we have a class 'Parent' , that for some reason has __new__
defined and a class 'Child' that inherits from it.
(In my case I'm trying to inherit from a 3rd party class that I cannot modify)
class Parent:
def __new__(cls, arg):
# ... something important is done here with arg
My attempt was:
class Child(Parent):
def __init__(self, myArg, argForSuperclass):
Parent.__new__(argForSuperclass)
self.field = myArg
But while
p = Parent("argForSuperclass")
works as expected
c = Child("myArg", "argForSuperclass")
fails, because 'Child' tries to call the __new__
method it inherits from 'Parent' instead of its own __init__
method.
What do I have to change in 'Child' to get the expected behavior?