Skip to content

Instantly share code, notes, and snippets.

@bersace
Created June 11, 2015 11:54
Show Gist options
  • Save bersace/b6be37c3d67992b58016 to your computer and use it in GitHub Desktop.
Save bersace/b6be37c3d67992b58016 to your computer and use it in GitHub Desktop.
partial-bound-method
import sys
from functools import partial
class A(object):
def meth(self):
return 'orig'
def newmeth(self):
assert isinstance(self, A)
return 'new'
a = A()
assert a.meth() == 'orig'
a.meth = partial(newmeth, a)
assert a.meth() == 'new'
a.meth = partial(A.meth, a)
assert a.meth() == 'orig'
print >>sys.stderr, 'OK'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment