[Python-ideas] Boolean parameters guidelines

Guido van Rossum guido at python.org
Mon May 9 18:35:20 EDT 2016


On Mon, May 9, 2016 at 2:57 PM, M.-A. Lemburg <mal at egenix.com> wrote:

> Hmm, so if you'd typically pass in a constant for the parameter
> it's deemed poor style, whereas when the value comes from some
> variable, it's fine ?
>

Yes.


> This looks more like an API design question than a coding
> style one.
>

Yes. IIRC the question that started this thread was about API design
guidance.


> E.g. take this example:
>
> def process(data, raise_errors=True):
>     try:
>         ...
>         return result
>     except ValueError:
>         if raise_errors:
>             raise
>         else:
>             return None
>
> It's not clear whether the caller would run the function
> with raise_errors=True or raise_errors=config.raise_errors
> more often.
>

Yeah, that's for the API designer to guess based on how they envision the
API to be used. It's often pretty clear once you start writing some example
code though.

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


More information about the Python-ideas mailing list