[Python-Dev] Order of positional and keyword arguments (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Fri Apr 27 05:59:38 EDT 2018


On Thu, 26 Apr 2018 22:25:09 +0300 Serhiy Storchaka <storchaka at gmail.com> wrote:

f(b=2, *[1]) is surprised in two ways: 1. Argument values are passed not in order. The first value is assigned to the second parameter, and the second value is assigned to the first parameter.

I don't find it that surprising. If you write f(b=2, a=1), you are also passing arguments "not in order", but it still looks ok to me.

2. Argument values are evaluated not from left to right. This contradicts the general rule that expressions are evaluated from left to right (with few known exceptions).

Well... If you have code that relies on that rule, I would agree it's brittle code and should be rewritten differently (perhaps by assigning to temporary variables explicitly).

Regards

Antoine.



More information about the Python-Dev mailing list