It seems like you can dynamically change Base.__bases__ if Base.__base__ not an object . (By dynamically changing, I mean so that all pre-existing instances that inherit from Base also dynamically change. Otherwise, see Nikolai Kharechko's decision ).
If Base.__base__ is some dummy TopBase class, then assigning Base.__bases__ seems to work:
class Extender(object): def extension(self): print("Some work...") class TopBase(object): pass class Base(TopBase): pass b=Base() print(Base.__bases__)
This has been tested to work in Python 2 (for new and old style classes) and for Python 3. I have no idea why this works until it is:
class Extender(object): def extension(self): print("Some work...") class Base(object): pass Base.__bases__ = (Extender, object)
unutbu
source share