Skip to content

Instantly share code, notes, and snippets.

@roman-kh
Created April 29, 2020 13:22
Show Gist options
  • Save roman-kh/baa4a9ae44b05b653073691276c5d561 to your computer and use it in GitHub Desktop.
Save roman-kh/baa4a9ae44b05b653073691276c5d561 to your computer and use it in GitHub Desktop.
# methods can be used as decorators
class A:
def awesome(method):
def wrapped(self, *args, **kwargs):
# do whatever you want
return method(self, *args, **kwargs)
return wrapped
@awesome
def some_method(self, *args, **kwargs):
print('some method', args, kwargs)
class B(A):
# it does not work here, because awesome is not in the namespace
@awesome
def another_method(self):
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment