Question about inheritance...

Alex Martelli aleaxit at yahoo.com
Sat Oct 22 21:48:07 EDT 2005


KraftDiner <bobrien18 at yahoo.com> wrote:

> Well here is a rough sketch of my code...
> This is giving my two problems.
> 
> 1) TypeError: super() argument 1 must be type, not classobj

Make your classes new-style (have Shape inherit from object) to fix
this.  You're using the legacy (old-style) object model (which remains
for backwards compatibility only).

> 2) I want to be sure the the draw code calls the inherited classes
> outline and not its own...

Call anything on self, and you'll use the inherited class.


> class Shape:

change to: class Shape(object):

>       def __init__(self):
>               pass

remove this method, no need for it.

>       def render(self):
>               print self.__class___

Use two trailing underscores, NOT three.

>               self.outline()
>       def outline(self):
>               pass

Use as the body "raise NotImplementedError" to make sure that
Shape.outline never gets accidentally called.

> 
> class Rect(Shape):
>       def __init__(self):
>               super(self.__class__, self).__init__()
>       def render(self):
>               super(self.__class__, self).draw()

You never defined a method named 'draw', do you mean 'render'?

>       def outline(self):
>               print 'outline' + self.__class__



Alex



More information about the Python-list mailing list