| def deco1(f):
|
| def _wrapper(*args, **kwargs):
|
| print("Hello from deco1()")
|
| return f(*args, **kwargs)
|
| return _wrapper
|
|
|
|
|
| def deco2(f):
|
| def _wrapper(*args, **kwargs):
|
| print("Hello from deco2()")
|
| return f(*args, **kwargs)
|
| return _wrapper
|
|
|
|
|
| @deco2
|
| @deco1
|
| def func(x):
|
| print(f"This is func({x=})")
|
|
|
|
|
| def other_func(x):
|
| print(f"This is other_func({x=})")
|
|
|
| # equivalent to above
|
| other_func = deco2(deco1(other_func))
|
|
|
|
|
| func(42)
|
| print("---")
|
| other_func(42)
|
| 18:56 [snoopjedi@denton ~/scratch]
|
| $ python3 thuna.py
|
| Hello from deco2()
|
| Hello from deco1()
|
| This is func(x=42)
|
| ---
|
| Hello from deco2()
|
| Hello from deco1()
|
| This is other_func(x=42)
|