[Pyrex] Re: cdef class and classmethod

Phillip J. Eby pje at telecommunity.com
Mon Sep 20 16:42:39 CEST 2004


At 03:18 PM 9/20/04 +1200, Greg Ewing wrote:
>Martin Field <mjfield at ibs.fr>:
>
> > I've tried to define a classmethod for a Pyrex extension type
> > (i.e. "cdef class") but it does not seem to work.
>
>You can't do that, at least not in the obvious way. You might be able
>to slip it into the class's __dict__ after creation (i.e. using code
>outside the class body), but you'll probably have to use
>PyDict_SetItem, since the __dict__ of a type object is protected
>against modification by normal means.

I don't think PyDict_SetItem will work, unless you get the *real* 
dictionary (because __dict__ returns a dict-proxy, not a dictionary).  I'm 
curious though, if this would work:


     def something(cls,etc):
         pass


     cdef class thing:
         something = classmethod(something)


If not, then perhaps in a subclass...






More information about the Pyrex mailing list