Overriding base class methods in the C API

F

Floris Bruynooghe

Hello

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?

Cheers
Floris
 
G

Gabriel Genellina

En Sun, 18 Jan 2009 22:18:59 -0200, Floris Bruynooghe
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top