Basic usage
Input
@log_args\ndef add(a, b):\n return a + b\n\nadd(2, 3)\nadd.log[-1]
Output
args=(2, 3), kwargs={}
After calling add(2, 3) the decorator stores a string representing the args and kwargs in add.log.
Full lesson preview
Create a decorator that records each call's positional and keyword arguments. Learn to use functools.wraps and attach metadata to the wrapped function.
Problem statement
Task
Examples
Input
@log_args\ndef add(a, b):\n return a + b\n\nadd(2, 3)\nadd.log[-1]
Output
args=(2, 3), kwargs={}
After calling add(2, 3) the decorator stores a string representing the args and kwargs in add.log.
Input format
Output format
Constraints
Samples
Input
add(1, 2)
Output
3
The decorated add returns the sum, and its log also receives an entry for the call.