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

Don Spaulding donspauldingii at gmail.com
Fri Jul 15 19:22:03 CEST 2011


On Fri, Jul 15, 2011 at 9:18 AM, Mike Graham <mikegraham at gmail.com> wrote:

> 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.
>

Glad to hear it.

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110715/ec675c04/attachment.html>


More information about the Python-ideas mailing list