So, basically my python wrapper is not working because it's not identifying an import statement I used at the start of my code. Here's my code:
# Decorator para imprimir o tempo de execução de uma função
import functools
import time
def timer(func):
@functools.wraps(func)
def timer_wrapper(*args, **kwargs):
start_time = time.perf_counter()
value = func(*args, **kwargs)
end_time = time.perf_counter()
time = end_time - start_time
print(f'Finished {func.__name__} in {time:.4f} secs')
return value
return timer_wrapper
@timer
def some_func(n):
time.perf_counter
for i in range(n):
sum([ j*2 for j in range(n)])
some_func(121)
Here's the exception:
Traceback (most recent call last):
File "decorator.py", line 22, in <module>
some_func(121)
File "decorator.py", line 9, in timer_wrapper
start_time = time.perf_counter()
UnboundLocalError: local variable 'time' referenced before assignment
Oddilly enough, it works inside other functions(see some_func()).
What's going on? My python version is 3.8.10