[IronPython] staticmethod / classmethod and setattr
Curt Hagenlocher
curt at hagenlocher.org
Thu Feb 7 00:49:24 CET 2008
Nice find, thanks. I guess I won't feel so bad about requiring a specific
order when defining static methods for "CLR export".
On Feb 6, 2008 3:46 PM, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> From http://www.ddj.com/web-development/184406073
>
> Usually, most decorators expect a function on input, and return either a
> function or an attribute descriptor as their output. The Python
> built-ins classmethod, staticmethod, and property all return attribute
> descriptors, so their output cannot be passed to a decorator that
> expects a function. That's why I had to put classmethod first in Listing
> Four. As an experiment, try reversing the order of @traced and
> @classmethod in Listing Four, and see if you can guess what will happen.
>
>
> Curt Hagenlocher wrote:
> > This is really more of a Python question than an IronPython question,
> > but I'm not currently on any non-Iron Python lists. :)
> >
> > The following definition results in an error under both CPython 2.5
> > and IronPython. Decorating a method as static or class prevents
> > attributes being set on the resulting definition.
> >
> > def decorate(obj):
> > obj.decorated = True
> > return obj
> >
> > class X:
> > @decorate
> > @staticmethod
> > def foo():
> > pass
> >
> > Does anyone know the "why" of this behavior?
> >
> > I can work around this problem by declaring the decorators in the
> > opposite order, but it seems like an odd imposition to put on the
> > consumers of the code in question. I'm worried that I'm missing
> > something about the expected semantics of these standard functions.
> >
> > --
> > Curt Hagenlocher
> > curt at hagenlocher.org <mailto:curt at hagenlocher.org>
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080206/7870f91e/attachment.html>
More information about the Ironpython-users
mailing list