[Python-ideas] Boolean parameters guidelines

Franklin? Lee leewangzhong+python at gmail.com
Sat May 14 19:26:50 EDT 2016

On May 12, 2016 4:29 AM, "Serhiy Storchaka" <storchaka at gmail.com> wrote:
> On 12.05.16 02:48, Chris Angelico wrote:
>>>>> from time import sleep
>>>>> help(sleep)
>> Help on built-in function sleep in module time:
>> sleep(...)
>>      sleep(seconds)
>>      Delay execution for a given number of seconds.  The argument may be
>>      a floating point number for subsecond precision.
>>>>> sleep(seconds=1)
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> TypeError: sleep() takes no keyword arguments
> Note that passing positional arguments is much faster than passing
keyword arguments even if the function supports them. And the difference
can be even larger after pushing Victor's optimization. [1]
> Other optimizations (like [2]) can be applied only for functions that
support only positional parameters. Thus passing positional arguments and
having functions that support only positional parameters is important for
> [1] http://bugs.python.org/issue26814
> [2] http://bugs.python.org/issue23867

Worth noting that a guarding optimizer, or a "hinted" optimizer (like a
decorator on the caller which locks in specified names for functions), can
theoretically optimize away those keyword args to positional args. So if
performance is important, there could be a future where readability doesn't
have to be sacrificed, and this idiom would put pressure on creating that

(Victor's other work on optimization is about both of those kinds of
optimizers, I think. I suggested this optimization, but never did anything
about it. It's on the todo list:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160514/bc23ff47/attachment-0001.html>

More information about the Python-ideas mailing list