
For function definitions, the introduction of `*` to mark keyword-only parameters was consistent with existing syntax in a sense that `def foo(*args, bar)` had `args` consume all positional arguments, so `bar` can only be passed via keyword. Now using `def foo(*, bar)` just omits the positional argument part, but leaves `bar` unchanged. However for function calls you can have positional arguments following argument unpacking: def foo(a, b): print(a, b) a, b = 2, 1 foo(*[], b, a) # prints "1 2" Now omitting the unpacking part would change the meaning of what follows, namely that it is to be interpreted as keyword arguments: foo(*, b, a) # prints "2 1" Sure you could argue that a lonely `*` in a function call has to have some effect, so it must change what comes after it, but this slight asymmetry between definition and calling of a function could be confusing. On 16.04.20 19:54, Alex Hall wrote:
I beg to differ. I do find "def foo(a, *, b)" gets in the way of readability.
-- Rhodri James *-* Kynesim Ltd
In what way?
In any case, focusing on the calling syntax being proposed, is there anything unreadable about:
foo(a, *, b)
compared to
foo(a, b=b)
? I think in the proposed syntax it's quite easy to understand that we're passing arguments 'a' and 'b' even if we have no idea what the '*' means, and it's small enough that it's fairly easy to mentally filter out.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/NWJTHD... Code of Conduct: http://python.org/psf/codeofconduct/