Files
Learn-Python-Programming-Th…/ch06/decorators/syntax.py
T
adii1823 b6eb3ef8a7 ch06
2021-10-28 17:38:47 +05:30

41 lines
598 B
Python

# decorators/syntax.py
# This is not a valid Python module - Don't run it.
# ONE DECORATOR
def func(arg1, arg2, ...):
pass
func = decorator(func)
# is equivalent to the following:
@decorator
def func(arg1, arg2, ...):
pass
# TWO DECORATORS
def func(arg1, arg2, ...):
pass
func = deco1(deco2(func))
# is equivalent to the following:
@deco1
@deco2
def func(arg1, arg2, ...):
pass
# DECORATOR WITH ARGUMENTS
def func(arg1, arg2, ...):
pass
func = decoarg(arg_a, arg_b)(func)
# is equivalent to the following:
@decoarg(arg_a, arg_b)
def func(arg1, arg2, ...):
pass