fork(1) download
  1. class A(object):
  2.  
  3. @classmethod
  4. def demo_method(cls, a):
  5. print(a)
  6.  
  7.  
  8. def decorator(function):
  9. from functools import wraps
  10. @wraps(function)
  11. def wrapper(*args, **kwargs):
  12. return_value = function(*args, **kwargs)
  13. return return_value
  14.  
  15. return wrapper
  16.  
  17.  
  18. setattr(A, 'demo_method', decorator(A.demo_method))
  19.  
  20. A.demo_method(1)
  21.  
Runtime error #stdin #stdout #stderr 0.01s 23296KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 20, in <module>
TypeError: unbound method demo_method() must be called with A instance as first argument (got int instance instead)