Ie, if I have a class MyClass, and I do super(MyClass).init, how can I tell which class’s init is actually going to be called?
Some code to illustrate:
class MyClass(OtherClass, ThirdClass):
def __init__(self):
mySuper = super(MyClass)
if mySuper == SomeClass:
# doesn't work - mySuper is a super object (not a normal class object)
pass
if mySuper.__init__ == SomeClass.__init__:
# doesn't work - mySuper.__init__ is a super-method-wrapper object
pass
if mySuper.__thisclass__ == SomeClass:
# doesn't work - __thisclass__ is set to be MyClass, not the "parent" class
pass
Any ideas?
EDIT:
If I hadn’t already awarded points here, I would probably delete this question, as it’s not really very useful as posed, and could potentially encourage bad habits.
As sven-marnach notes, I’m using the one-arg version, super(MyClass), instead of the more useful two-arg version, super(MyClass, self)… and now, I have no idea why I would have wanted to do that. My best guess is that I was still unclear on the proper usage of super at the time.
If you’re using the two-arg version, then the second check works – with the caveat that you would need to get .im_func, ie:
if mySuper.__init__.im_func == SomeClass.__init__.im_func:
See Determine whether super().__new__ will be object.__new__ in Python 3? for an example of why this sort of check is useful…
You can extract the wrapped class using
This looks complex, but I also think it is rather pointless to do this.
Edit: I just noticed you don’t pass
selftosuper(). For that case, you could useThe question that remains is: why would you want to do this?