Skip to content

Instantly share code, notes, and snippets.

@att14
Last active April 25, 2019 08:32
Show Gist options
  • Select an option

  • Save att14/5711647 to your computer and use it in GitHub Desktop.

Select an option

Save att14/5711647 to your computer and use it in GitHub Desktop.
Decorators can be dangerous
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
@MosesFu
Copy link

MosesFu commented Apr 25, 2019

Thanks for explain the order of decorators execute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment