First of all, here is my (pseudo) code:
somemodule.py:
class parentclass(object):
def __init__(self):
if(not prevent_infinite_reursion) #Just to make shure this is not a problem ;)
self.somefunction()
def somefunction():
# ... deep down in a function ...
# I want to "monkey patch" to call constructor of childclass,
# not parentclass
parentclass()
othermodule.py
from somemodule import parentclass
class childclass(parentclass):
def __init__(self):
# ... some preprocessing ...
super(childclass, self).__init__()
The problem is, i want to monkey patch parent class, so it would call constructor of childclass, without changing code of somemodule.py. It doesn't matter if it's patched only in class instance(that's shure better) or globally.
I know i can override somefunction, but it contains too many lines of code, for this being sane.
Thanks!