[Python-ideas] __missing__ object/keyword

George Sakkis george.sakkis at gmail.com
Thu Nov 6 22:15:49 CET 2008

On Thu, Nov 6, 2008 at 3:47 PM, Greg Falcon <veloso at verylowsodium.com>wrote:

On Thu, Nov 6, 2008 at 3:31 PM, George Sakkis <george.sakkis at gmail.com>
> wrote:
> > Several times I find myself using the following idiom:
> >
> > _Missing = object()   # sentinel
> >
> > def foo(x, y=_Missing):
> >   if y is _Missing:
> >     do_this
> >   else:
> >     do_that
> > It would be nice if a new object or keyword, say __missing__, was
> > introduced as a canonical way to address this common scenario.
> > Thoughts ?
> This has been proposed and shot down before:
> http://mail.python.org/pipermail/python-dev/2007-May/073439.html
> The older proposal didn't give __missing__ the special run-time and
> compile-time error behaviors,

I agree that it doesn't make sense without special compile/runtime behavior;
that would be like adding a second None.

> but this actually just makes things
> worse. Why complicate the language merely to save a single idiomatic
> line of code dealing with a relatively infrequent use-case?

I can't tell how much it would complicate the implementation of the language
but the semantics are pretty straightforward. But you have a point there,
None is more often than not an adequare sentinel, so if implementing
__missing__ requires significant work it's probably not worth the effort.

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

More information about the Python-ideas mailing list