You can check whether the function has already been seen:
def do_all(self):
seen = set()
for c in reversed(self.__class__.__mro__[:-1]):
if c.do_it not in seen:
seen.add(c.do_it)
c.do_it(self)
Note that in Python 2 you'll need to extract the function from the unbound method, as c.do_it.__func__
(or use six.get_unbound_function
).
An alternative is to examine __dict__
:
def do_all(self):
for c in reversed(self.__class__.__mro__[:-1]):
if 'do_it' in c.__dict__:
c.do_it(self)