[Python-Dev] PEP 573 -- Module State Access from C Extension Methods

Jeroen Demeyer J.Demeyer at UGent.be
Tue Apr 24 04:17:42 EDT 2018


In PEP 573, instead of passing the defining class to the C function, why 
not pass the function object itself? That is far more general: once you 
have the function object, you can still access the defining class using 
your PyCMethod_CLASS. It's also more future-proof: if we ever decide to 
add even more attributes to the function object, those could be accessed 
the same way.

In PEP 575, I'm already proposing a flag (METH_ARG0_FUNCTION) to pass 
the function *instead* of self. Unless PEP 573 is rejected, maybe that 
should change to passing the function *in addition* to self.

Of course, this doesn't quite work with your current version of PEP 573 
since METH_METHOD really does two things: it changes the class of the 
function object (which is not a good idea anyway) and it changes the 
calling convention. It could work if you add mm_class to 
PyCFunctionObject instead of creating a new class.


Jeroen.


More information about the Python-Dev mailing list