bazelbuild / starlark

Starlark Language
Apache License 2.0
2.44k stars 160 forks source link

Permit multiple **kwargs arguments #178

Open ndmitchell opened 3 years ago

ndmitchell commented 3 years ago

Given the function call f(**a, **b) the meaning is clear and precise. But the best Starlark-compliant alternative I could find is:

x = dict(a)
a.update(b)
f(**x)

That seems more complex, and it's easy to get it wrong, and it doesn't error if a key is repeated (unlike before).

Given an extension to multiple **kwargs, I see no reason not to allow it for *args too, although there the argument is weaker.

illicitonion commented 3 years ago

We could instead support the python3 {**a, **b} syntax for constructing/merging dicts, which would make your call instead look like:

f(**{**a, **b})

which is valid python3.

ndmitchell commented 3 years ago

Yep, that would be great too.