Python Argument Surprise

Python function signatures are flexible, complex beasts, allowing for positional, keyword, variable, and variable keyword arguments (and parameters). This can be extremely useful, but sometimes the intersection between these features can be confusing or even surprising, especially on Python 2. What do you expect this to return?

>>> def test(arg1, **kwargs):
...     return arg1
>>> test(**{'arg1': 42})

Read more…