On Mon, May 25, 2020 at 3:42 AM David Mertz <[email protected]> wrote:
> The pattern:
>
> def fun(..., option=None):
>     if option is None:
>         option = something_else
>
> Becomes second nature very quickly.  Once you learn it, you know it.  A line 
> of two of code isn't a big deal.
>

And it isn't entirely correct, because now None isn't a valid
parameter. It's an extremely common idiom right up until it doesn't
work, and you need:

_SENTINEL = object()
def fun(..., option=_SENTINEL):
    if option is _SENTINEL:
        option = something_else

Now, try doing that for multiple parameters at once. Or in a closure.
Or anything else that would make it more complicated.

ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/6OUVR6UEQAYEOOUQRUOWP7SOXVDZN3XE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to