[Python-ideas] Boolean parameters guidelines
Joseph Martinot-Lagarde
contrebasse at gmail.com
Tue May 10 09:15:40 EDT 2016
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)
More information about the Python-ideas
mailing list