Skip to content

Commit 11b60e3

Browse files
authored
Refactor decorator to copy metadata manually
Removed functools.wraps and manually copied metadata to the wrapper function.
1 parent cc09128 commit 11b60e3

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎Week04/decorators_yagiz_cengiz.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import functools
21
import time
32
import tracemalloc
43

@@ -9,7 +8,6 @@ def performance(fn):
98
The statistics of all decorated functions are saved in its attributes.
109
"""
1110

12-
@functools.wraps(fn)
1311
def wrapper(*args, **kwargs):
1412
# shortcut: a decorated function calling another one under-reports
1513
# memory because tracemalloc is global, keep calls flat to stay exact
@@ -23,6 +21,9 @@ def wrapper(*args, **kwargs):
2321
performance.counter += 1
2422
tracemalloc.stop()
2523

24+
# copy the metadata by hand instead of functools.wraps
25+
wrapper.__name__ = fn.__name__
26+
wrapper.__doc__ = fn.__doc__
2627
return wrapper
2728

2829

0 commit comments

Comments
 (0)