Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Overriding base class methods in the C API

Reply
Thread Tools

Overriding base class methods in the C API

 
 
Floris Bruynooghe
Guest
Posts: n/a
 
      01-19-2009
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
 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-19-2009
En Sun, 18 Jan 2009 22:18:59 -0200, Floris Bruynooghe
<(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Problem with method overriding from base class Python 2 03-31-2008 08:37 PM
Overriding base class James Emil Avery C++ 4 07-26-2007 01:39 AM
overriding base class alf Python 2 06-30-2007 06:45 AM
overriding method that returns base class object Stuart McGraw Python 10 02-17-2004 04:48 PM



Advertisments