multiple-inheritance

conditional class inheritance in python

conditional class inheritance in python Question: I am trying to dynamically create classes in Python and am relatively new to classes and class inheritance. Basically I want my final object to have different types of history depending on different needs. I have a solution but I feel there must be a better way. I dreamed …

Total answers: 3

Multiple inheritance in python3 with different signatures

Multiple inheritance in python3 with different signatures Question: I have three classes: A, B and C. C inherits from A and B (in this order). The constructor signatures of A and B are different. How can I call the __init__ methods of both parent classes? My endeavour in code: class A(object): def __init__(self, a, b): …

Total answers: 1

How does multiple inheritance work with the super() and different __init__() arguments?

How does multiple inheritance work with the super() and different __init__() arguments? Question: I’m just diving into some more advanced python subjects (well, advanced to me at least). I am now reading about multiple inheritance and how you can use super(). I more or less understand the way the super function is used, but (1) …

Total answers: 2

Python's Multiple Inheritance: Picking which super() to call

Python's Multiple Inheritance: Picking which super() to call Question: In Python, how do I pick which Parent’s method to call? Say I want to call the parent ASDF2’s __init__ method. Seems like I have to specify ASDF1 in the super()..? And if I want to call ASDF3’s __init__, then I must specify ASDF2?! >>> class …

Total answers: 3

Calling parent class __init__ with multiple inheritance, what's the right way?

Calling parent class __init__ with multiple inheritance, what's the right way? Question: Say I have a multiple inheritance scenario: class A(object): # code for A here class B(object): # code for B here class C(A, B): def __init__(self): # What’s the right code to write here to ensure # A.__init__ and B.__init__ get called? There’s …

Total answers: 11

Triple inheritance causes metaclass conflict… Sometimes

Triple inheritance causes metaclass conflict… Sometimes Question: Looks like I stumbled upon a metaclass hell even when I didn’t wanted anything to do with it. I’m writing an app in Qt4 using PySide. I want to separate event-driven part from UI definition, which is generated from Qt Designer files. Hence I create a “controller” classes, …

Total answers: 2

Are Mixin class __init__ functions not automatically called?

Are Mixin class __init__ functions not automatically called? Question: I’d like to use a Mixin to always add some init functionality to my child classes which each inherit from different API base classes. Specifically, I’d like to make multiple different child classes that inherit from one of these different API-supplied base classes and the one …

Total answers: 4

Is super() broken in Python-2.x?

Is super() broken in Python-2.x? Question: It’s often stated that super should be avoided in Python 2. I’ve found in my use of super in Python 2 that it never acts the way I expect unless I provide all arguments such as the example: super(ThisClass, self).some_func(*args, **kwargs) It seems to me this defeats the purpose …

Total answers: 5

How to avoid infinite recursion with super()?

How to avoid infinite recursion with super()? Question: I have code like this: class A(object): def __init__(self): self.a = 1 class B(A): def __init__(self): self.b = 2 super(self.__class__, self).__init__() class C(B): def __init__(self): self.c = 3 super(self.__class__, self).__init__() Instantiating B works as expected but instantiating C recursed infinitely and causes a stack overflow. How can …

Total answers: 1

python multiple inheritance from different paths with same method name

python multiple inheritance from different paths with same method name Question: With the following code sample, can super be used, or C has to call A.foo and B.foo explicitly? class A(object): def foo(self): print ‘A.foo()’ class B(object): def foo(self): print ‘B.foo()’ class C(A, B): def foo(self): print ‘C.foo()’ A.foo(self) B.foo(self) Asked By: sayap || Source …

Total answers: 9