Advertisement
bozhilov

Bind decorators to a class' methods

Sep 1st, 2023
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.23 KB | None | 0 0
  1. def bind_decorator(obj: Any, decorator: Any) -> None:
  2.     methods = [
  3.         method for method,
  4.         _ in inspect.getmembers(obj, inspect.ismethod)
  5.     ]
  6.     for method in methods:
  7.         setattr(obj, method, decorator(method))
  8.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement