1

I have a usecase where i need to add a new parent class at run time for an already instantiated class in python. What would be the best way to achieve this?

To clarify a bit more :

Suppose we have a OriginalBaseClass and a child class derived from the original OriginalBaseClass. Now we have an object A of the child class and at run time we need to add a new class called NewBaseClass as one of the parent classes of child class object A (along with OriginalBaseClass).

Is this even possible? I would love to hear your thoughts. Thank you.

qwerty123
  • 479
  • 1
  • 3
  • 14
  • 1
    This seems like a sign that you're using inheritance for the wrong things. Dynamically adding new classes to individual objects is a very strange way to use inheritance. – user2357112 Feb 18 '19 at 18:41
  • I would have definitely tried to avoid this if possible. This is just a very weird usecase that i have to solve as the part of a project that im doing. I need to use a third party function and to use this function, my parameter object needs to be in inherited from one of their class. – qwerty123 Feb 18 '19 at 18:46
  • 1
    Possible duplicate of [How to dynamically change base class of instances at runtime?](https://stackoverflow.com/questions/9539052/how-to-dynamically-change-base-class-of-instances-at-runtime) – Matias Cicero Feb 18 '19 at 18:49

0 Answers0