Created
April 29, 2020 13:22
-
-
Save roman-kh/baa4a9ae44b05b653073691276c5d561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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