[Python-3000] The case for unbound methods?
Anthony Tolle
artomegus at gmail.com
Mon Mar 10 00:53:49 CET 2008
On Sun, Mar 9, 2008 at 6:31 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
> No, a wrapper can't distinguish between a plain function and
> an unbound method this way, because it gets called before the
> function is put into a class. So it's always wrapping a plain
> function, not an unbound method object.
>
Witness:
>>> def wraptest(func):
... print "I'm wrapping an instance of ", type(func)
... return func
...
>>> class C(object):
... @wraptest
... @staticmethod
... def s():
... pass
... @wraptest
... @classmethod
... def c():
... pass
... @wraptest
... def i():
... pass
...
I'm wrapping an instance of <type 'staticmethod'>
I'm wrapping an instance of <type 'classmethod'>
I'm wrapping an instance of <type 'function'>
>>>
More information about the Python-3000
mailing list