""" This is a demonstration of a bug that occurs when using _functools.partial output as a method """ from functools import partial as cpartial def pypartial(func, *args, **keywords): """ This implementation is copied from http://www.python.org/doc/2.5.2/lib/module-functools.html """ def newfunc(*fargs, **fkeywords): newkeywords = keywords.copy() newkeywords.update(fkeywords) return func(*(args + fargs), **newkeywords) newfunc.func = func newfunc.args = args newfunc.keywords = keywords return newfunc def method_new(self, creator): print "method created by %s called with instance of %s as self" % (creator, self.__class__.__name__) print class Thingy(): partial_py = pypartial(method_new, creator='pypartial') partial_c = cpartial(method_new, creator='cpartial') cpartial(method_new, self="a string", creator='cpartial')() Thingy().partial_py() Thingy().partial_c() # fails