Adding Sum as Decorator

  • Share this:

Code introduction


This function accepts two arguments and returns a decorator that adds the sum of all arguments passed to the decorated function to the original function's return value.


Technology Stack : Decorator, function, variable-length argument list

Code Type : Function

Code Difficulty : Advanced


                
                    
def aaaaaaa(arg1, arg2):
    def bbbbbbb(func):
        def wrapper(*args, **kwargs):
            return func(arg1, arg2) + sum(args)
        return wrapper
    return bbbbbbb