Unpacking arguments: only named arguments may follow *expression

As Raymond Hettinger’s answer points out, this may change has changed in Python 3 and here is a related proposal, which has been accepted.
Especially related to the current question, here’s one of the possible changes to that proposal that was discussed:

Only allow a starred expression as the last item in the exprlist. This would simplify the
unpacking code a bit and allow for the starred expression to be assigned an iterator. This
behavior was rejected because it would be too surprising.

So there are implementation reasons for the restriction with unpacking function arguments but it is indeed a little surprising!

In the meantime, here’s the workaround I was looking for, kind of obvious in retrospect:

f(*(a+[3]))

Leave a Comment