如何在 Python 中使用继承的装饰器?
class Foo:
@staticmethod
def keyErrorOnRed(f, colour):
if colour == "red":
raise KeyError("Better dead than red")
return lambda: f(*args, **kwargs)
class Bar(Foo):
@keyErrorOnRed("red")
def __init__(self, a, b):
self.vars = a, b
if __name__ == '__main__':
barObj = Bar('can', 'haz')