I'd like to update some parent class in a python module to add a feature to all children classes. The module is installed via pip
.
If I can modify the parent class, I just add methods to it. But, I should not edit installed modules. (following my previous discussion)
How can I add a feature to all children classes inside a python package without editing files inside pip package directories?
One alternative is using monkeypatching, but seems too tricky.
Update
Concrete situation is that I'd like to add common method to Child1
and Child2
, but can not edit Parent because it is a class of a pip
package.
class Parent:
...
class Child1(Parent):
...
class Child2(Parent):
...