E
E
Evstolyan2021-10-23 00:29:31
Python
Evstolyan, 2021-10-23 00:29:31

What is the RecursionError in the decorator function?

from math import factorial
from timeit import default_timer as timer


def how_much_time(func):
    def wrapper_1(*args, **kwargs):
        start = timer()
        summator(*args, **kwargs)
        finish = timer()
        print(f"Time: {finish-start} in {func.__name__}")

    return wrapper_1

@how_much_time
def summator(number):
    print(f"Answer: {factorial(number)}")


summator(10)


Hello! After executing this code, the following error occurs:

File "C:\Users\Comp\Desktop\Learning\Python\decorator\logging_decorator.py", line 7, in wrapper_1
start = timer()
RecursionError: maximum recursion depth exceeded while calling a Python object


What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
antares4045, 2021-10-23
@Evstolyan

wrapper_1 should call func and not summator:
you ended up replacing the adder with a wrapper around something that calls the adder, which in turn is a wrapper around the adder... and so on ad infinitum

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question