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

Steven D'Aprano steve at pearwood.info
Sun Mar 4 23:28:15 CET 2012


Serhiy Storchaka wrote:
> 04.03.12 23:23, Greg Ewing написав(ла):
>> Another bikeshed idea on positional-only parameters:
>>
>> def foo([self], a, b, *args, **kwds):
>> ...
>>
>> The square brackets are meant to suggest that the name is
>> something only of interest to the implementation of the function,
>> and not to be taken as part of the API.

Please do not give syntactic meaning to [parameter], unless it matches the 
existing convention for optional parameters.

Besides, positional-only arguments are not only of interest to the 
implementation, they are part of the API.


> Or _name, as for "private" class and module members.

In my own functions, I use _name for private implementation arguments, and 
usually explicitly document that callers should not rely on them. In the 
implementation, sometimes I need to use that private argument, and I always do 
so by name so that it stands out that I'm using a special argument, e.g. 
something like:


def func(spam, ham, cheese, _name=eggs):
     if condition:
         x = func(spam, ham, cheese, _name=beans)
     ...


If you also overload _name to also mean "positional only", I would have to write

         x = func(spam, ham, cheese, beans)

which looks like a "normal" argument.

And as already mentioned, the use of _name to mean positional-only and private 
would clash with functions which want public positional-only.


-- 
Steven




More information about the Python-ideas mailing list