17 lines
574 B
Python
17 lines
574 B
Python
from functools import wraps
|
|
|
|
def log_args_decorator(func):
|
|
"""
|
|
A decorator that logs the arguments passed to a function.
|
|
"""
|
|
@wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
arg_names = func.__code__.co_varnames[:func.__code__.co_argcount]
|
|
pos_args = dict(zip(arg_names, args))
|
|
all_args = {**pos_args, **kwargs}
|
|
|
|
print(f"Calling function '{func.__name__}' with arguments: {all_args}")
|
|
result = func(*args, **kwargs)
|
|
print(f"Function '{func.__name__}' returned: {result}")
|
|
return result
|
|
return wrapper |