super problem

Discussion in 'Python' started by Uwe Mayer, Jun 25, 2005.

  1. Uwe Mayer

    Uwe Mayer Guest

    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
     
    Uwe Mayer, Jun 25, 2005
    #1
    1. Advertising

  2. 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
     
    Michael Hoffman, Jun 25, 2005
    #2
    1. Advertising

  3. On 6/25/05, Uwe Mayer <> 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
     
    Konstantin Veretennicov, Jun 25, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    super.super.super how?

    Guest, Feb 19, 2005, in forum: Java
    Replies:
    24
    Views:
    10,872
    Darryl Pierce
    Feb 24, 2005
  2. Fernando Rodriguez

    Getting the super class via the super() function

    Fernando Rodriguez, Nov 21, 2003, in forum: Python
    Replies:
    2
    Views:
    752
    Bob Willan
    Nov 22, 2003
  3. Kerim Borchaev

    super. could there be a simpler super?

    Kerim Borchaev, Jan 15, 2004, in forum: Python
    Replies:
    4
    Views:
    493
    Michele Simionato
    Jan 15, 2004
  4. Replies:
    7
    Views:
    450
    Patricia Shanahan
    Apr 6, 2008
  5. GOOD LUCK GROUP
    Replies:
    0
    Views:
    418
    GOOD LUCK GROUP
    Apr 28, 2008
Loading...

Share This Page