From bd4bcdc8d309fec9c0af62c039bc15c49d151344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 28 Jan 2019 20:40:58 +0100 Subject: [PATCH] Decorator --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1182031..c093bb5 100644 --- a/README.md +++ b/README.md @@ -599,9 +599,11 @@ def get_counter(): Decorator --------- +**A decorator takes a function, adds some functionality and returns it.** + ```python -@closure_name -def function_that_gets_passed_to_closure(): +@decorator_name +def function_that_gets_passed_to_decorator(): ... ``` @@ -638,17 +640,17 @@ def fib(n): CacheInfo(hits=28, misses=16, maxsize=None, currsize=16) ``` -### Parametrized Decorator +### Parametrized Example ```python def debug(print_result=False): - def inner_decorator(func): + def decorator(func): @wraps(func) def out(*args, **kwargs): result = func(*args, **kwargs) print(func.__name__, result if print_result else '') return result return out - return inner_decorator + return decorator @debug(print_result=True) def add(x, y):