[Python-ideas] Boolean parameters guidelines

Serhiy Storchaka storchaka at gmail.com
Thu May 12 04:28:16 EDT 2016


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 performance.

[1] http://bugs.python.org/issue26814
[2] http://bugs.python.org/issue23867




More information about the Python-ideas mailing list