[Python-Dev] Using descriptors to dynamically attach methods written in Python to C-defined (new-style) types

Travis Oliphant oliphant at ee.byu.edu
Sat Mar 26 00:13:43 CET 2005


In updating Numeric to take advantage of the new features in Python, 
I've come across the need
to attach a Python-written function as a method to a C-builtin.  I don't 
want to inherit, I just want to extend the methods of a builtin type 
using a Python function.   I was thinking of updating the new type 
objects dictionary with a new entry that is a descriptor object.

It seems that the descriptor mechanism makes this a relatively 
straightforward thing.  My question is, can I use the already-available 
Descriptor objects to do this, or will I need to define another 
Descriptor object.  (Perhaps a PythonMethod descriptor object to 
complement the Method Descriptor). 

Any hints will be helpful.  

-Travis Oliphant





More information about the Python-Dev mailing list