470,811 Members | 1,144 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,811 developers. It's quick & easy.

super problem

Hi,

I have a diamond-shaped multiple inheritanc chain with new style classes,
but super() does not call the parent class correctly:

-- snip --
from qtcanvas import *

class B2(QCanvasItem):
def move(self, x,y):
super(B2, self).move(0,0)
print "B2"

class C2(QCanvasItem):
def move(self, x,y):
super(C2, self).move(0,0)
print "C2"

class D2(QCanvasPolygonalItem, B2, C2):
def move(self, x,y):
super(D2, self).move(0,0)
print "D2"

d2 = D2(None)
d2.move(0,0)
-- snip --
returns:

Traceback (most recent call last):
File "tmp.py", line 46, in ?
d2.move(0,0)
File "tmp.py", line 42, in move
super(D2, self).move(0,0)
File "tmp.py", line 32, in move
super(B2, self).move(0,0)
File "tmp.py", line 37, in move
super(C2, self).move(0,0)
AttributeError: 'super' object has no attribute 'move'

super(C2, self).move(0,0) should resolve to QCanvasItem.move
AFAIK super only works with new-style classes, so I checked:
from qtcanvas import *
isinstance(QCanvasItem, object)

True
A way to fix this is to introduce a dummy

class A2(QCanvasItem):
def move(self,x,y): QCanvasItem.move(self,x,y)

This is stupid, as it only delays execution by one intermediary call.
Is this a bug?

Thanks,
Ciao
Uwe
Jul 19 '05 #1
2 1281
Uwe Mayer wrote:
I have a diamond-shaped multiple inheritanc chain with new style classes,
but super() does not call the parent class correctly:

-- snip --
from qtcanvas import *


I don't have qtcanvas installed, and I couldn't reproduce the
undesirable behavior using a dummy class. If you try to create a
self-contained testcase, you will have an easier time figuring where the
problem is.
--
Michael Hoffman
Jul 19 '05 #2
On 6/25/05, Uwe Mayer <me*****@hadiko.de> wrote:
AFAIK super only works with new-style classes, so I checked:
from qtcanvas import *
isinstance(QCanvasItem, object) True


AFAIK, this is not the right way to check for new-styledness:
class X: "i'm an old-styler"
isinstance(X(), object) True

But this is:
isinstance(X, type)

False

- kv
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Clarence Gardner | last post: by
11 posts views Thread by Nicolas Lehuen | last post: by
9 posts views Thread by Paul Rubin | last post: by
2 posts views Thread by Michael P. Soulier | last post: by
6 posts views Thread by David Hirschfield | last post: by
4 posts views Thread by John Salerno | last post: by
4 posts views Thread by Noah | last post: by
5 posts views Thread by Erwan Adam | last post: by
12 posts views Thread by iu2 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.