I'm having trouble accessing the default keyword argument value within a decorator. If I pass in a value to the decorated function's keyword parameter, I can access the keyword argument value in the decorator just fine. Otherwise, I cannot access the keyword argument value.
Here is a working example of a decorator and a decorated function:
def print_args_kwargs(func):
def wrapper(*args, **kwargs):
print(args, kwargs)
return func(*args, **kwargs)
return wrapper
@print_args_kwargs
def say_hi(text='hi'):
return text
No dice:
say_hi()
>>> (), {}
This works:
say_hi(text="hello")
>>> (), {"text": "hello"}