I’ve stumbled in a tricky python question. Given (updated):
class A(object):
def run(self):
# This makes possible to determine if 'run' was overridden
if self.run.im_func != A.run.im_func:
print('Running in {0}'.format(self.__class__.__name__))
class B(A):
def run(self):
super(B, self).run()
class C(A):
pass
b = B()
c = C()
b.run()
>>> Running in B
c.run()
>>> # nothing :)
How would you design the @runoverriden decorator, that would do the job of conditional statement in A.run()?
Update:
The purpose of this code is that A.run() should log the run() calls , only if it has been overridden.
Thank you!
If I understand what you want: