0
class Base(object):
    def __init__(self):
        super(Base, self).__init__()
        print 'base ctor'
        self._visible = False

    def get_visible(self):
        return self._visible

    def set_visible(self, value):
        print 'Base set visible'
        self._visible = value       

    def __visible_get(self):
        return self.get_visible()

    def __visible_set(self, value):
        if self.visible != value:
            self.set_visible(value)

    visible = property(__visible_get, __visible_set)

class Base2(object):
    def __init__(self):
        super(Base2, self).__init__()
        print 'base2 ctor'

    def set_visible(self, value):
        print 'base2 setvisible'       

class Drv(Base2, Base):
    def __init__(self):
        super(Drv, self).__init__()
        print 'base2 ctor'

    def set_visible(self, value):
        print 'Drv setvisible'
        super(Drv, self).set_visible(value)

d = Drv()
d.visible = True
d.visible = False

Question is Drv.set_visible() won't call Base.set_visible(), which is not expected. In normal case, if there are two method with same name in base classes, the super(Drv).fuc() will call the both. Why not in this case?

kylieCatt
  • 10,672
  • 5
  • 43
  • 51
Joey.Z
  • 4,492
  • 4
  • 38
  • 63
  • 1
    Because `Base2.set_visible` doesn't call `super`? – jonrsharpe Aug 06 '14 at 15:14
  • 5
    *In normal case, if there are two method with same name in base classes, the super(Drv).fuc() will call the both.*. Where did you get that idea from? That is **not** the case. `super()` **only** calls the one in the next base class listed in the MRO. – Martijn Pieters Aug 06 '14 at 15:14
  • 1
    This covers it nicely: http://stackoverflow.com/questions/3277367/how-does-pythons-super-work-with-multiple-inheritance – Jeff Langemeier Aug 06 '14 at 15:14

0 Answers0