Decorator to log the input params and the return value of a function

PHOTO EMBED

Mon Nov 14 2022 10:45:32 GMT+0000 (Coordinated Universal Time)

Saved by @taha #python #decorator

def log_params(func):
    def wrapper(*args, **kwargs):
        return_value = func(*args, **kwargs)
        print(f"{args} -> {return_value}")

    return wrapper


@log_params
def summation(a: int, b: int) -> int:
    return a + b


summation(10, 20)
content_copyCOPY