473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1350
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Clarence Gardner | last post by:
The super object is considered a solution to the "diamond problem". However, it generally requires that the ultimate base class know that it is last in the method resolution order, and hence it...
11
by: Nicolas Lehuen | last post by:
Hi, I hope this is not a FAQ, but I have trouble understanding the behaviour of the super() built-in function. I've read the excellent book 'Python in a Nutshell' which explains this built-in...
9
by: Paul Rubin | last post by:
I'm trying the super() function as described in Python Cookbook, 1st ed, p. 172 (Recipe 5.4). class A(object): def f(self): print 'A' class B(object): def f(self):
2
by: Michael P. Soulier | last post by:
Ok, this works in Python on Windows, but here on Linux, with Python 2.4.1, I'm getting an error. The docs say: A typical use for calling a cooperative superclass method is: class C(B):...
6
by: David Hirschfield | last post by:
I'm having trouble with the new descriptor-based mechanisms like super() and property() stemming, most likely, from my lack of knowledge about how they work. Here's an example that's giving me...
4
by: John Salerno | last post by:
Here's some code from Python in a Nutshell. The comments are lines from a previous example that the calls to super replace in the new example: class A(object): def met(self): print 'A.met' ...
4
by: Noah | last post by:
Am I the only one that finds the super function to be confusing? I have a base class that inherits from object. In other words new style class: class foo (object): def __init__ (self, arg_A,...
5
by: Erwan Adam | last post by:
Hi all, I have a problem with the use of descriptors and super. The file is : # --------------- class Desc(object): def __init__(self, class_name): self.class_name = class_name
12
by: iu2 | last post by:
Hi I'm trying to make a method call automatically to its super using this syntax: class A: chained = def pr(self): print 'Hello from A'
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.