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

Serhiy Storchaka storchaka at gmail.com
Mon Mar 5 09:27:28 CET 2012

05.03.12 00:28, Steven D'Aprano написав(ла):
> Serhiy Storchaka wrote:
>> 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.

There is no clash. Both the application means the same thing -- you 
advise a client not to use this name as keyword argument. Of course, he 
may, but need not, if not aware.

'spam'.find('a', _end=1) looks terrible and no one will inadvertently 
use it.

Or use a double underscore for the reinforcement to prevent the use of 
this name. def find(self, sub, __start=0, __end=None)

More information about the Python-ideas mailing list