Creating Subclassable Objects??
Greg Ewing
see_reply_address at something.invalid
Thu Jul 4 21:26:02 EDT 2002
Pete Shinners wrote:
> At this point you are able to subclass the objects, the problem is they
> just don't work. If my new class has an __init__ method, it seems i
> cannot properly instance the objects (since it needs some args).
I'm just guessing here (I haven't played with this stuff
much myself) but if your subclass's __init__ takes different
arguments from the base class, you may need to override
the __new__ method as well as the __init__ method, e.g.
class MySubclass(SomeExtensionType):
def __new__(self, my_args):
return SomeExtensionType.__new__(...base class args...)
def __init__(self, my_args):
SomeExtensionType.__init__(...base class args...)
...more init...
> If I
> don't have an __init__ method, i can instance the new class, but none of
> the new methods i add to it work (AttributeError).
I don't know what might be causing that. Are you sure you've
done all the necessary things to make your extension type
subclassable? Have you put PyObject_Generic{Get,Set}Attribute
in the appropriate type slots?
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list