can I call operator overloader in superclass?
Jon J. Morin
rotundo52 at hotmail.com
Thu Jun 20 01:17:00 EDT 2002
Erik Max Francis wrote:
> "Jon J. Morin" wrote:
>
>> TypeError: repr not string
>>
>> For one, I don't understand the error. For seconds, can I call
>> __repr__ in
>> the superclass from __repr__ in the subclass?
>
> I'm guessing you have an older version of Python. In Python 2.2 this is
> the error you'll get:
>
> TypeError: __repr__ returned non-string (type NoneType)
>
> which I can only presume was changed to be a little more descriptive.
> The calling superclass methods in subclasses is actually leading you
> astray -- all the error is telling you is that your __repr__ method must
> return and yours isn't. Change the __repr__ method in your subclass so
> that it returns a string and you're off and running.
>
> To answer your other question (which really wasn't the issue here), you
> can certainly explicitly call a superclass method in a subclass, and
> you'd had the syntax right: Specify the superclass method is an unbound
> method and then explicitly pass in the self object:
>
> class Superclass:
> ...
>
> def method(self):
> ...
>
> class Subclass(Superclass):
> ...
>
> def method(self):
> ...
> Superclass.method(self)
> ...
>
>
Thanks. All I forgot was a return statement in the subclass method and it
works now. Thanks for the help.
Jon
More information about the Python-list
mailing list