Passing kwargs... can overwrite other keyword arguments

This is working as intended and documented:

The nature of keyword arguments makes it possible to specify the same argument more than once. For example, in the call plot(x, y; options..., width=2) it is possible that the options structure also contains a value for width . In such a case the rightmost occurrence takes precedence; in this example, width is certain to have the value 2 . However, explicitly specifying the same keyword argument multiple times, for example plot(x, y, width=2, width=3) , is not allowed and results in a syntax error.

I think it’s the right behavior: f(; a=4, a=8) is most probably an error, but f(; a=4, kwargs...) and f(; kwargs..., a=4) can both be very useful: with the first one you can let the caller override your value of a, and with the second one you can override what the caller passes.

I find this feature very useful…

4 Likes