[Python-ideas] None-as-sentinel alternatives? (was: deferred default arguments)

Mike Graham mikegraham at gmail.com
Fri Jul 15 16:18:47 CEST 2011


On Fri, Jul 15, 2011 at 10:05 AM, Don Spaulding
<donspauldingii at gmail.com> wrote:
> When I come across a situation where I want a sentinel that doesn't preclude
> None from being a valid value, I've always spelled it like this:
>     SENTINEL = object()  # Guaranteed to be unique and not None.
>
>     def f(arg=SENTINEL):
>         if arg is SENTINEL:
>             arg = 'foo'
>         x(arg)
> It's always worked well, but that little voice in my head tells me there's
> probably something I'm not thinking of that will come back to bite me in the
> future.  I don't think this helps the OP in any meaningful way, but I was
> wondering if you bright people might shed some light on the drawbacks of
> this approach for me.  What are the better alternatives?

No, this approach isn't error-prone.

For non-idea questions you might consider comp.lang.python in the future.  =)


Mike



More information about the Python-ideas mailing list