Subclassing a C type

Jason Lai cejlai at lafn.org
Thu Apr 17 02:52:01 EDT 2003


Actually, nevermind, I found another part of the program that was 
tampering with the inheritance. Works well enough for me now.

Jason Lai wrote:
> Hello,
> 
> I wrote a Python type in C, Actor, and created a subclass Tester 
> (new-style classes). Actor has a getattro function that gets information 
> from elsewhere in the C program.
> 
> Apparently, the Tester class inherits tp_getattro from Actor. What I'd 
> like it to do is have it use the regular lookup so that it checks its 
> own dict before deferring to its parent classes. Without having to 
> define a __getattr__ function on Tester. Maybe I could change the 
> __getattr__ on every tp_new, but that seems a bit messy.
> 
> I thought about having Actor_getattro look up the value in 
> Tester-instances' dictionaries, but I don't think it would work if there 
> were more subclasses between Actor and Tester in the hierarchy.
> 
> And I do need to intercept the getattro calls, so I can't just use the 
> standard object one and define tp_members/tp_methods.
> 
> Am I doing something wrong?
> 
> Thanks in advance for any advice you can offer,
> 
>  - Jason Lai
> 





More information about the Python-list mailing list