Parametrized inheritance

Dan Bullok dan.ng at bullok.com
Sat Jan 3 19:59:42 EST 2004


I have a couple of classes:
    class Base:
        ...

    class Sub(Base):
        ...


I want to subclass Base and Sub, i.e. define classes:
    class MyBase(Base):
        ...

    class MySub(Sub):
        ... 

The inheritance looks like this: 
    Base->MyBase
        ->Sub->MySub

But I'd really like it to look like this:
    Base->MyBase->Sub->MySub

i.e. define Sub as "class Sub(X)", where I can change X at the time of
instantiation.  Then I could define MySub as "class MySub(Sub(MyBase))".
(I hope that it's obvious that I'm looking for this effect, not this syntax)


Of course, someone is going to ask "why?"

I need to override a few members in Base.  Sub is mostly fine as-is, so if I
could have MySub=Sub(MyMBase), that would be fine.



    

                



More information about the Python-list mailing list