fork download
  1. class Foo:
  2. @staticmethod
  3. def keyErrorOnRed(colour):
  4. def decorate(f):
  5. def wrapped(*args, **kwargs):
  6. if colour == "red":
  7. raise KeyError("Better dead than red")
  8. return f(*args, **kwargs)
  9. return wrapped
  10. return decorate
  11.  
  12. class Bar(Foo):
  13. @Foo.keyErrorOnRed("red")
  14. def __init__(self, a, b):
  15. self.vars = a, b
  16.  
  17. if __name__ == '__main__':
  18. barObj = Bar('can', 'haz')
Runtime error #stdin #stdout #stderr 0.01s 7724KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 18, in <module>
    barObj = Bar('can', 'haz')
  File "prog.py", line 7, in wrapped
    raise KeyError("Better dead than red")
KeyError: 'Better dead than red'