Today we had to patch a class function in production. Monkey patching can become tricky if reference are kept at several place like pointer in C and C++.Share on Reddit!!!
Here is a simple example on how to make sure all references will use the new definition.class Foo:This is another reason why interpreter language like python are so powerful.
def f(self):
print "default f"
def newf(self):
print "newf"
Foo.f.im_func.func_code = newf.func_code
Wednesday, July 21, 2010
patching class function in python
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment