Bootstrap

TypeError: unsupported operand type(s) for *: ‘int‘ and ‘NoneType‘

from time import time
def wrapper_1(func):
    def inner(*args,**kwargs):
        start_time = time()
        func(*args,**kwargs)
        end_time = time()
        print(f"此次调用函数共计耗时:{end_time - start_time}")
    return inner
@wrapper_1
def fun(x):
    if x == 1 or x == 0:
        return 1
    return x * fun(x - 1)
fun(4)

此为错误代码
错误原因为:

我装饰了fun函数,使得fun函数不再指向原本的函数体,而是指向了inner的函数体,而inner函数体我并没有给返回值,所以会在return x * fun(x - 1)处发生报错

;