title: How to declare a python c-extension method as a classmethod?
body: <p>I'm writing a python wrapper for a C++ class that provide several static methods for alternate "constructors". I'm wondering how to export these through the python c-api? </p>
  
  <p>Here is a stub of the relevant C++ code.</p>
  
  <pre><code> PyObject *PyFoo_FromFoo(Foo foo);
  
   // This should be a class method that create a new instance of PyFoo().
   PyObject *
   PyFoo_Gen1(PyObject *self, PyObject *args)
   {
       Foo foo;  // Init this according to args
  
       return PyFoo_FromFoo(foo);
   }
  
   static PyMethodDef PyFoo_methods[] = {
      {"Gen1", (PyCFunction)PyFoo_Gen1, METH_VARARGS, "Gen1 foo creator" },
      {NULL}  /* Sentinel */
   };
  
   PyTypeObject PyFooType = {
     :
     PyFoo_methods, /* tp_methods */
     :
   }
  
   PyObject *PyFoo_FromFoo(Foo foo)
   {
      PyFoo *v = (PyFoo*)PyObject_New(PyFoo, &amp;PyFooType);
      v-&gt;foo = foo;
      return (PyObject*)v;
   }
  </code></pre>
  
  <p>What would be the corresponding of using the <code>classmethod()</code> function (directly or through the <code>@classmethod</code> decorator) for <code>Gen1()</code> in the example above? </p>