[Python-ideas] Boolean parameters guidelines

Guido van Rossum guido at python.org
Tue May 10 12:00:13 EDT 2016


On Tue, May 10, 2016 at 6:15 AM, Joseph Martinot-Lagarde <
contrebasse at gmail.com> wrote:

> Serhiy Storchaka <storchaka at ...> writes:
>
> > 1. It is preferable to pass boolean arguments as keyword arguments (if
> > this is not the only argument).
> >
> > 2. It is preferable to declare boolean parameters as keyword-only
> > parameters.
> >
>
> It is true for literal keywords arguments, but passing a named variable
> with
> a boolean value can be fine.
>
>     # Bad
>     my_func(True)
>
>     # Good
>     my_func(enable=True)
>
>     # Good
>     enable=True
>     my_func(enable)
>
>     # Meh
>     enable=True
>     my_func(enable=enable)
>
>     # Bad
>     w=True
>     my_func(w)
>

That list of examples seems to be aligned along the wrong axis.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160510/c708bcc7/attachment.html>


More information about the Python-ideas mailing list