I'm confused about storing methods in class dictionaries from the point of view of the C API.
1. Let's say that I have a callable PyObject called f, of my type defined in C. I want to store something derived from f as A.m for some class A, such that for an object a of class A, calling a.m(*args) ends up calling f(a, *args). In Python2 PyMethod_New(f, NULL, a) seems to be the right to store in the class. How to do the equivalent thing in Python3? BTW, applying PyMethod_Type to 3 arguments crashes Python3. I think this line is the culprit (classobject.c): if (!PyArg_UnpackTuple(args, "method", 2, 3, &func, &self)) Should be 2 instead of 3. There used to be an extra parameter. 2. As above, but f is to be implemented as a C function. I found the following working for a new-style class: - make PyMethodDef struct for the method - use PyDescr_NewMethod - store the resulting object in the class but it does not work for a classic class (such that an exception class in Python 2.4 and below) to which I want to add a method. Here it seems to be doable differently: - make PyMethodDef struct for the method, but with an unused first parameter - use PyCFunction_New, with NULL as 'self' - use PyMethod_New on the resulting function, NULL, and the class - store the resulting object in the class Can this be done simpler? Having separate variants for different Python versions is OK. -- __("< Marcin Kowalczyk \__/ [EMAIL PROTECTED] ^^ http://qrnik.knm.org.pl/~qrczak/ _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com