Last active
April 25, 2019 08:32
-
-
Save att14/5711647 to your computer and use it in GitHub Desktop.
Decorators can be dangerous
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 double(func): | |
| def wrapped(*args, **kwargs): | |
| return func(*args, **kwargs) * 2 | |
| return wrapped | |
| def increment(func): | |
| def wrapped(*args, **kwargs): | |
| return func(*args, **kwargs) + 1 | |
| return wrapped | |
| @double | |
| @increment | |
| def plus_one_doubled(x): | |
| return x | |
| @increment | |
| @double | |
| def double_plus_one(x): | |
| return x | |
| plus_one_doubled(5) # 12 | |
| double_plus_one(5) # 11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for explain the order of decorators execute.