Skip to content

Commit cef1cea

Browse files
committed
Decorator
1 parent b32d5f7 commit cef1cea

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,13 @@ def function_that_gets_passed_to_decorator():
608608
```
609609

610610
### Debugger Example
611+
**"Wraps" decorator copies metadata of function func() to function out(). Without it `add.__name__` would return `'out'`.**
612+
611613
```python
612614
from functools import wraps
613615

614616
def debug(func):
615-
@wraps(func) # Copies func's metadata like name and doc to out.
617+
@wraps(func)
616618
def out(*args, **kwargs):
617619
print(func.__name__)
618620
return func(*args, **kwargs)
@@ -625,6 +627,7 @@ def add(x, y):
625627

626628
### LRU Cache
627629
**Decorator that caches function's return values. All arguments must be hashable.**
630+
628631
```python
629632
from functools import lru_cache
630633

@@ -634,10 +637,10 @@ def fib(n):
634637
```
635638

636639
```python
637-
>>> [fib(n) for n in range(16)]
638-
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]
640+
>>> [fib(n) for n in range(8)]
641+
[0, 1, 1, 2, 3, 5, 8, 13]
639642
>>> fib.cache_info()
640-
CacheInfo(hits=28, misses=16, maxsize=None, currsize=16)
643+
CacheInfo(hits=12, misses=8, maxsize=None, currsize=8)
641644
```
642645

643646
### Parametrized Decorator

0 commit comments

Comments
 (0)