Decorator Python Library Hide The Kwargs Inside Args
I got a pretty weird behaviour with the decorator library which is explained in the next code: from decorator import decorator @decorator def wrap(f, a, *args, **kwargs):
Solution 1:
Just because you call the function with b=2 does not make b a keyword argument; b is a positional argument in the original function. If there were no argument named b and you specified b=2, thenb would become a keyword argument.
decorator's behavior is actually the most correct; the wrapper it generates has the same signature as funcion(), whereas the wrapper made by your "homemade" decorator does not have b as a named argument. The "homemade" wrapper "incorrectly" puts b in kwargs because the signature of myfuncion(), which makes it clear that b is not a keyword arg, is hidden from the caller.
Preserving the function signature is a feature, not a bug, in decorator.
Post a Comment for "Decorator Python Library Hide The Kwargs Inside Args"