naparuba/shinken — pull request #1402 by gst (2014-11-30 14:14:20+00:00)
Title: fix: bad super call. would infinitely recurse if subclassed..

Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> class A(object):
def x(self):
return 42

>>> class B(A):
def x(self):
sup = super(self.__class__, self).x
print("in B: ", sup)
return sup()

>>> b = B()

## if not subclassed, then ok :

>>> b.x()
('in B: ', >)
42
>>>

>>> class C(B): pass # but if subclassed ..

>>> import sys
>>> sys.setrecursionlimit(50)
>>>
>>> c = C()
>>> c.x()
('in B: ', >)
('in B: ', >)
('in B: ', >)

Traceback (most recent call last):
File "", line 1, in
c.x()
File "", line 5, in x
return sup()
File "", line 5, in x
return sup()
File "", line 5, in x
return sup()
File "", line 4, in x
print("in B: ", sup)
File "/usr/lib/python2.7/idlelib/PyShell.py", line 1351, in write
return self.shell.write(s, self.tags)
RuntimeError: maximum recursion depth exceeded while calling a Python object
>>>

Always use the "bare" or literal class of where is happening the super call , so here :

>>> class B(A):
def x(self):
sup = super(B, self).x
return sup() + 1

>>> class C(B): pass

>>> C().x()
43
>>>