| f | from functools import wraps | f | from functools import wraps |
| | | |
| def counter(func): | | def counter(func): |
| n | calls_count = 0 | n | count = 0 |
| | | |
| @wraps(func) | | @wraps(func) |
| def wrapper(*args, **kwargs): | | def wrapper(*args, **kwargs): |
| n | nonlocal calls_count | n | nonlocal count |
| calls_count += 1 | | count += 1 |
| return func(*args, **kwargs) | | return func(*args, **kwargs) |
| | | |
| def counter_method(): | | def counter_method(): |
| t | return calls_count | t | return count |
| wrapper.counter = counter_method | | wrapper.counter = counter_method |
| return wrapper | | return wrapper |