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])
| 2 | |
| 3 | |
| 4 | class 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 | |
| 25 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected