[IronPython] staticmethod / classmethod and setattr

Michael Foord fuzzyman at voidspace.org.uk
Wed Feb 6 15:44:37 PST 2008

Not really an answer but possibly an explanation. staticmethod and 
classmethod are descriptors that wrap callable objects. Because they are 
implemented in C they us __slots__ and you can't set arbitrary 
attributes on them.


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

More information about the Users mailing list