[Python] Unexpected None Return from Decorated Function in Python [closed]

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a simple decorator that logs when a function is called. However, after applying the decorator, my function’s return value is unexpectedly None. Here’s my code:

    def logger_decorator(func):
    def wrapper(*args, **kwargs):
    print(f"Calling {func.name} with {args}")
    result = func(*args, **kwargs)
    return wrapper

    @logger_decorator
    def add(x, y):
    return x + y

    print(add(2, 3))


    my expected result was supposed to be 5 but it returns None

    Continue reading...

Compartilhe esta Página