On Sun, Mar 9, 2008 at 7:53 PM, Anthony Tolle <[EMAIL PROTECTED]> wrote: > On Sun, Mar 9, 2008 at 6:31 AM, Greg Ewing <[EMAIL PROTECTED]> 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'> > >>> >
Sorry about replying to myself, but I should clarify: That particular point in my post was about checking the type of wrapped object *before* calling __get__ on it, to see whether or not I'm wrapping a static method. The theory is, if I don't see 'staticmethod' or 'classmethod', then simple deduction tells me I'm going to get either a bound method or an unbound method. Whether it is bound or unbound won't be known until I check what is returned by __get__. Of course, the other point was that this would only work on the first wrapper around @staticmethod or @classmethod. I wasn't offering it as a real solution. _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com