[Pyrex] Re: cdef class and classmethod

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Sep 21 03:29:29 CEST 2004


> I don't think PyDict_SetItem will work, unless you get the *real*
> dictionary (because __dict__ returns a dict-proxy, not a
> dictionary).

You may be right, in which case something even more devious would be
required. I know it's possible for C code to put things in the type
dict, I just haven't looked into the details of how it's done.

> I'm curious though, if this would work:
> 
>      def something(cls,etc):
>          pass
> 
>      cdef class thing:
>          something = classmethod(something)

No, that won't even come close to working. Despite the syntactic
similarity between Python class and extension type definitions in
Pyrex, they're utterly different beasts underneath. An extension type
definition is purely declarative -- you can't put any executable
statements inside it.

> If not, then perhaps in a subclass...

You can create a Python subclass of the extension type and put class
methods in that, if you want.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list