python – What is the correct use of arguments that consist only of keywords?

Argument-only arguments are arguments that can only be passed to a function by keyword. In Python, they are defined by a single asterisk in the signature of a function. For example:

>>> def foo (bar, *, baz):
print (bar, baz)
>>> foo (1, baz = 2)
1 2
>>> foo (1, 2)
TypeError: foo () takes 1 positional argument, but 2 are specified

It has always seemed to me a good practice to force a user to use keyword arguments for a variety of reasons:

  • As you read the code, you can clearly see what you are passing to a function. You do not have to worry about a function definition.

  • It is less error prone. If there are positional arguments in a function call, changing a signature can lead to errors. For keyword arguments, there is no such problem.

  • Explicit is better than implicit.

However, when I published a question in a CodeReview Stack Exchange (Generation of Julia Set), an examiner said that he did not agree with this compelling of keyword arguments because:

"It should be up to the caller to determine if the addition is explicit
kwarg names makes the call clearer, or if the parameters are there
Passed are obvious and the code can be made scarcer.

And I kind of agree with that, because "We agree with all adults here".

I could not find a general description of how to properly use the arguments in PEP 3102 that you suggested. PEP 8 mentions nothing about it.

My question is: how should I use the arguments correctly for the keyword only?

I understand that this question probably has no final answer, but I am not looking for a conversation. What I want are application examples with explanations why it should be.