[Python-ideas] keyword arguments everywhere (stdlib) - issue8706

Steven D'Aprano steve at pearwood.info
Tue Mar 6 01:00:31 CET 2012


Greg Ewing wrote:
> Steven D'Aprano wrote:
> 
>> Please do not give syntactic meaning to [parameter], unless it matches 
>> the existing convention for optional parameters.
> 
> Why should it have to do that? We already have a syntax for
> optional parameters, and there is no reason for a reader to
> think that a new piece of syntax is simply duplicating existing
> functionality.

I see your later comment about metasyntax, but to clarify in case there is 
still any lingering doubt what I mean:

When reading function signatures in *documentation*, we often see 
func([parameter]) used to indicate that parameter is an optional argument. If 
your proposal is enacted, when reading function signatures in *code*, we will 
see func([parameter]) used to indicate that you can't use parameter as a 
keyword argument.

The two uses clash, which means that every time we see a [parameter] in a 
function signature, there will be a moment of disorientation where we have to 
decide whether it should be interpreted using the convention for code or the 
convention for documentation.

Certainly there are ways of distinguishing the two from context, particularly 
if the default value is shown in the signature, or from subtleties of whether 
the comma is inside the brackets or not, or perhaps from the order ([] early 
in the signature probably means positional, [] at the end probably means 
optional).

My point is not that it is impossible to distinguish optional from positional 
arguments, but that the similarity of syntax makes it difficult to distinguish 
the two *at a glance* and comprehensibility will be reduced.

And heaven help us if we have a function like range with positional-only 
optional parameters:

range([[start]=0,] [end] [, [step]=1]) --> iterable

For the avoidance of doubt, I am *not* suggesting that we introduce 
[parameter] as syntax for optional arguments. I don't want to see [] used 
syntactically inside def func(...) at all, except for the VERY rare use of 
lists as mutable default arguments.


-- 
Steven




More information about the Python-ideas mailing list