| Дю Василий Андреевич КФ МГУ FuncCount 8518 | Mikhailenko Alexandr Sergeevich 316 FuncCount 7539 | ||||
|---|---|---|---|---|---|
| f | 1 | from functools import wraps | f | 1 | from functools import wraps |
| 2 | 2 | ||||
| 3 | def counter(func): | 3 | def counter(func): | ||
| n | 4 | count = 0 | n | 4 | calls = 0 |
| 5 | 5 | ||||
| 6 | @wraps(func) | 6 | @wraps(func) | ||
| n | 7 | def wrapper(*a, **kw): | n | 7 | def wrapper(*args, **kwargs): |
| 8 | nonlocal count | 8 | nonlocal calls | ||
| 9 | count += 1 | 9 | calls += 1 | ||
| 10 | return func(*a, **kw) | 10 | return func(*args, **kwargs) | ||
| 11 | 11 | ||||
| t | 12 | def get(): | t | 12 | def get_calls(): |
| 13 | return count | 13 | return calls | ||
| 14 | wrapper.counter = get | 14 | wrapper.counter = get_calls | ||
| 15 | return wrapper | 15 | return wrapper | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||