Overriding base class methods in the C API

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jan 19 09:05:01 EST 2009


En Sun, 18 Jan 2009 22:18:59 -0200, Floris Bruynooghe  
<floris.bruynooghe at gmail.com> escribió:

> I've been trying to figure out how to override methods of a class in
> the C API.  For Python code you can just redefine the method in your
> subclass, but setting tp_methods on the type object does not seem to
> have any influcence.  Anyone know of a trick I am missing?

No tricks; you have to define the new type structure, probably including  
tp_methods if you redefine any... (Ensure you create an object of the new  
type, obviously)
See e.g. _collections.c how defaultdict inherits from dict.

-- 
Gabriel Genellina




More information about the Python-list mailing list