[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multiple inheritance, super() and changing signature

On Fri, Jun 3, 2016 at 8:06 AM, Nagy L?szl? Zsolt <gandalf at> wrote:
>>> That's overly strict. As Raymond shows, it is easy to deal with
>>> changing method signatures in *cooperative* classes.
>> I must watch that for sure.
> All right, I have read this:
> There is still something I don't get: how to create cooperative classes
> when some base classes share some of the parameters?

Why do they need to share the same parameter? Part of cooperative
design is that you can't really design each class in a vacuum; you
need to take the other classes they might get combined with into
account. Perhaps you can extract that parameter into another base
class that is shared by both:

class Root:
    def __init__(self, *, param1, **kwds):
        self.param1 = param1

class A(Root):
    def __init__(self, *, param2, **kwds):
        self.param2 = param2

class B(Root):
    def __init__(self, *, param3, **kwds):
        self.param3 = param3

class X(A, B):

A and B can both depend on having param1 without stomping on each
other because they both inherit Root which requires it.