Junior — Senior
Manual wrapping of a decorator
livecode
Task condition
Show how to manually wrap the generate_list function with the time_logger decorator, without using the @time_logger syntax, but by explicitly calling the decorator.
import time
def time_logger(func):
def wrapped(*args, **kwargs):
t_start = time.time()
result = func(*args, **kwargs)
t_end = time.time()
print(f'func ran in {t_end - t_start}')
return result
return wrapped
def generate_list(count: int) -> list[int]:
return [i for i in range(count)]
# manual application of the decorator
generate_list = time_logger(generate_list)