我有一个类是许多其他类的超类.我想知道(在我的超类的init()中,子类是否已覆盖特定方法.
我尝试使用类方法完成此操作,但结果是错误的:
class Super:
def __init__(self):
if self.method == Super.method:
print 'same'
else:
print 'different'
@classmethod
def method(cls):
pass
class Sub1(Super):
def method(self):
print 'hi'
class Sub2(Super):
pass
Super() # should be same
Sub1() # should be different
Sub2() # should be same
>>> same
>>> different
>>> different
Run Code Online (Sandbox Code Playgroud)
有没有办法让超类知道子类是否覆盖了一个方法?