Created
May 5, 2020 15:42
-
-
Save jaklinger/d2961e8cb21a95e5d5d3db5558d586fc to your computer and use it in GitHub Desktop.
after decorator example
This file contains hidden or 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
def do_the_other_thing(run, output): | |
def wrap(self): | |
run(self) | |
output(self) | |
return wrap | |
class A: | |
name='a' | |
def run(self): | |
pass | |
def hello(self): | |
print('hello') | |
def output(self): | |
self.hello() | |
def __init_subclass__(cls): | |
super().__init_subclass__() | |
cls.run = do_the_other_thing(cls.run, cls.output) | |
# do some other work | |
class B(A): | |
name='b' | |
def run(self): | |
print("running!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment