can I call operator overloader in superclass?

Erik Max Francis max at alcyone.com
Thu Jun 20 00:59:18 EDT 2002


"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)
	        ...


-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Who'd ever think it / Such a squalid little ending
\__/ The American and Florence, _Chess_
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list