Home > Software engineering >  I have this ERROR: TypeError: unsupported operand type(s) for *: 'int' and 'NoneType&
I have this ERROR: TypeError: unsupported operand type(s) for *: 'int' and 'NoneType&

Time:06-12

Could you tell me why do i have this error with my code: unsupported operand type(s) for *: 'int' and 'NoneType'

from datetime import datetime

def dec(f):
    def wrap(d):
        now = datetime.now()
        f(d)
        print(datetime.now() - now)
    return wrap

@dec
def fac(n):
    if n == 1:
        return n
    else:
        return n*fac(n-1)

fac(5)

CodePudding user response:

The wrapping function in your decorator needs to return the result from the decorated function

def dec(f):
    def wrap(d):
        now = datetime.now()
        result = f(d)
        print(datetime.now() - now)
        return result
    return wrap
  • Related