Closed devashishshankar closed 4 years ago
wow, very strange indeed ! This should definitely not happen. It is probably related to the fact that the __init__
descriptor is not called in an intuitive way by super
. I'll have a look, thanks a lot for reporting !
For some reason that seems to be a python bug, super(B, self).__init__(a)
is not equivalent to A.__init__(self, a)
when the __init__
method is a method descriptor: InitDescriptor.__get__(obj, objtype)
is called but when it is called through super, objtype
is not replaced with A
.
I'll have to find a workaround, that should not be too difficult. In the meantime, you can use A.__init__(self, a=self.a)
as a constructor, it works.
I found a workaround but for python 3.6+ (where __setname__
callback is called when the init descriptor is attached to the class). Unfortunately for earlier versions I still have no way to determine which class owns the init method to be created. I really thought that objtype
in InitDescriptor.__get__(obj, objtype)
was reliable...
Thanks, using A.__init__(self, a=self.a)
works for me.
I finally found a "clever" way to solve this :)
It will ship in 1.0.3
in a few minutes when travis has completed
Let's say I want to call superclass init in my child class:
This fails with the following Error:
If I try the following:
This leads to the following:
This is very dangerous, and was leading to a weird error in my code. Took me a while to figure out this was the cause.
I think the superclass constructor is being overriden by the child class.
setattr(objtype, '__init__', new_init)
ininit_makers.py
Is calling superclass constructor not supported?
I am using version 1.0.2