Menu

#1428 WRONG: Override template not respect Python Multiinheritance

open
5
2011-11-24
2011-11-24
No

Override is very nice feature but unfortunately currently in PyDev it change to wrong pattern - it generates code like that:

class B(A):
def overriden(self):
A.overriden(self)

But should respect polymorphism since currently lead to double calls of super super parents. Valid code should be:

class B(A):
def overriden(self):
super(B, self).overriden()

Why because - compare __init__ and chain behavior to your current implementation I called it 'strict' - valid code generates 4 calls in chain - static generates 5 calls (double call of super super parent:

Code bellow:

class SuperParent(object):
def __init__(self):
print 'SuperParent'

def chain(self):
print 'SuperParent'

def strict(self):
print 'SuperParent'

class Parent1(SuperParent):
def __init__(self):
super(Parent1, self).__init__()
print 'Parent1'

def hello(self):
print 'Parent1'

def chain(self):
super(Parent1, self).chain()
print 'Parent1'

def strict(self):
SuperParent.strict(self)
print 'Parent1'

class Parent2(SuperParent):
def __init__(self):
super(Parent2, self).__init__()
print 'Parent2'

def hello(self):
print 'Parent2'

def chain(self):
super(Parent2, self).chain()
print 'Parent2'

def strict(self):
SuperParent.strict(self)
print 'Parent2'

class Child1(Parent1, Parent2):
def __init__(self):
super(Child1, self).__init__()
print 'Child1'

def chain(self):
super(Child1, self).chain()
print 'Child1'

def strict(self):
Parent1.strict(self)
Parent2.strict(self)
print 'Child1'

class Child2(Parent2, Parent1):
def __init__(self):
super(Child2, self).__init__()
print 'Child2'

def chain(self):
super(Child2, self).chain()
print 'Child2'

def strict(self):
Parent2.strict(self)
Parent1.strict(self)
print 'Child2'

print '-' * 16
c = Child1()
print '-' * 8
c.hello()
print '-' * 8
c.chain()
print '-' * 8
c.strict()

print '-' * 16
c = Child2()
print '-' * 8
c.hello()
print '-' * 8
c.chain()
print '-' * 8
c.strict()

Calls results:

----------------
SuperParent
Parent2
Parent1
Child1
--------
Parent1
--------
SuperParent
Parent2
Parent1
Child1
--------
SuperParent
Parent1
SuperParent
Parent2
Child1
----------------
SuperParent
Parent1
Parent2
Child2
--------
Parent2
--------
SuperParent
Parent1
Parent2
Child2
--------
SuperParent
Parent2
SuperParent
Parent1
Child2

If you have quest ask freely.

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.