Skip to content

Commit d1a93c1

Browse files
authored
Update performance decorator metadata handling
Replaced functools.wraps with manual metadata preservation for the performance decorator.
1 parent 2437755 commit d1a93c1

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎Week04/decorators_ilyas_bugra_filoglu.py‎

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

54

65
def performance(func):
7-
@functools.wraps(func)
86
def wrapper(*args, **kwargs):
97
is_tracing = tracemalloc.is_tracing()
8+
109
if not is_tracing:
1110
tracemalloc.start()
11+
1212
tracemalloc.reset_peak()
1313

1414
start_time = time.perf_counter()
@@ -26,6 +26,14 @@ def wrapper(*args, **kwargs):
2626

2727
return result
2828

29+
# Manually preserve function metadata (replaces functools.wraps)
30+
wrapper.__name__ = func.__name__
31+
wrapper.__doc__ = func.__doc__
32+
wrapper.__module__ = func.__module__
33+
wrapper.__qualname__ = func.__qualname__
34+
wrapper.__annotations__ = func.__annotations__
35+
wrapper.__wrapped__ = func
36+
2937
return wrapper
3038

3139

0 commit comments

Comments
 (0)