[Python-Dev] METH_CLASS

Fred L. Drake, Jr. fdrake@acm.org
Thu, 25 Apr 2002 10:20:04 -0400


Thomas Heller writes:
 > Is the documentation wrong, or is the code wrong (I didn't find
 > any use of METH_CLASS in the CVS sources)?

There's an example in sandbox/datetime/datetime.c; search for
"datetime_now".

 > [I must say that I'm not really sure how this relates to the
 > calling convention flags. Have tried METH_O and METH_VARARGS
 > so far.]

Guido van Rossum writes:
 > You have to call classmethod() from C; it's available as
 > &PyClassMethod_Type, you can call it with e.g. PyObject_Call.  The
 > argument should be a function object that you created by calling
 > PyCFunction_New.  Then stick it into your type's tp_dict (after
 > calling PyType_Ready()).

I'll note that while this is a little tedious, it's easily packaged
into a helper function.


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation