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

Steven D'Aprano steve at pearwood.info
Sat Mar 3 03:57:52 CET 2012


Ethan Furman wrote:
> Guido van Rossum wrote:
>> On Fri, Mar 2, 2012 at 2:49 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>>> Terry Reedy wrote:
>>>> On 3/2/2012 3:32 PM, Ethan Furman wrote:
>>>>>>>>> So something like:
>>>>>>>>>> def ord(char, ?):
>>>>>>>>>> def split(self, char, ?, count)
>>>>>>>>>> def canary(breed, ?, color, wingspan, *, name)
>>>>>>>> That is probably better than using '$' or directly tagging the names.
>>>>>> I chose '?' because it has some similarity to an incompletely-drawn 
>>> 'p', and
>>> also because it suggests a sort of vagueness, as in not being able to
>>> specify the name of the argument.
>>>> I'd rather not start using a new punctuation character for this one
>> very limited purpose; it might prevent us from using ? for some other
>> more generic purpose in the future.
>>>> Alternative proposal: how about using '/' ? It's kind of the opposite
>> of '*' which means "keyword argument", and '/' is not a new character.
>>>> So it would look like:
>> def ord(char, /):
>> def split(self, char, /, count)
>> def canary(breed, /, color, wingspan, *, name)
>>> I think I like that better -- it stands out, and it looks like a barrier 
> between the positional-only and the positional-keyword arguments.

Urrggg, ugly and hard to read. Imagine, if you will:
def spam(x, /, y, /, z, /, a=2/3, /):
 ...
Placing the tag after the argument as an extra parameter is not the right 
approach in my opinion. It's excessively verbose, and it puts the tag in the 
wrong place: as you read from left-to-right, you see "normal argument, no, 
wait, it's positional only". The tag should prefix the name.
With keyworld-only arguments, the * parameter is special because it flags a 
point in the parameter list, not an individual parameter: you read "normal 
arg, normal arg, start keyword-only args, keyword-only arg, ...".
I believe that the right place to tag the parameter is in the parameter 
itself, not by adding an extra parameter after it. Hence, something like this:
def spam(~x, ~y, ~z, ~a=2/3):
 ...
where ~name means that name cannot be specified by keyword. I read it as "not 
name", as in, the caller can't use the name.
Or if you prefer Guido's pun:
def spam(/x, /y, /z, /a=2/3):
 ...
Much less line-noise than spam(x, /, y, /, z, /, a=2/3, /).
Personally, I think this is somewhat of an anti-feature. Keyword arguments are 
a Good Thing, and while I don't believe it is good enough to *force* all C 
functions to support them, I certainly don't want to discourage Python 
functions from supporting them.
-- 
Steven


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /