MCPcopy Create free account
hub / github.com/ActiveState/code / DoDefaultMixin

Class DoDefaultMixin

recipes/Python/279604_DoDefaultMixin/recipe-279604.py:4–22  ·  view source on GitHub ↗

An alternative way to call superclass method code. Mix this class in to your classes, and you can now use the following form to call superclass methods: retval = cls.doDefault([args]) instead of the usual: retval = super(cls, self).methodName([args])

Source from the content-addressed store, hash-verified

2
3
4class DoDefaultMixin(object):
5 ''' An alternative way to call superclass method code.
6
7 Mix this class in to your classes, and you can now use the following
8 form to call superclass methods:
9
10 retval = cls.doDefault([args])
11
12 instead of the usual:
13
14 retval = super(cls, self).methodName([args])
15 '''
16
17 def doDefault(cls, *args, **kwargs):
18 frame = sys._getframe(1)
19 self = frame.f_locals['self']
20 methodName = frame.f_code.co_name
21 return eval('super(cls, self).%s(*args, **kwargs)' % methodName)
22 doDefault = classmethod(doDefault)
23
24
25if __name__ == '__main__':

Callers

nothing calls this directly

Calls 1

classmethodFunction · 0.50

Tested by

no test coverage detected