How can I define a decorator decor
to make this work? There are a lot of posts about this but I'm still not finding a solution. Maybe it is a very bad idea.
Example 1, write a function that is broken until the decorator is applied:
defaults = {'a': 1, 'b': 2}
@decor(defaults)
def f(x):
print(x, a, b)
Example 2:
defaults = {'a': 1, 'b': 2}
@decor(defaults)
def fun(x):
print(locals())
f(3)
Should give
{'b': 2, 'x': 3, 'a': 1}
Or maybe to be clearer, I want the signature to be modified by the decorator so that help(f)
gives
Help on function f in module __main__:
f(x, a=1, b=2)