On Thu, Nov 6, 2008 at 3:47 PM, Greg Falcon <span dir="ltr"><<a href="mailto:veloso@verylowsodium.com">veloso@verylowsodium.com</a>></span> wrote:<br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Thu, Nov 6, 2008 at 3:31 PM, George Sakkis <<a href="mailto:george.sakkis@gmail.com">george.sakkis@gmail.com</a>> wrote:<br>
> Several times I find myself using the following idiom:<br>
><br>
> _Missing = object()   # sentinel<br>
><br>
> def foo(x, y=_Missing):<br>
>   if y is _Missing:<br>
>     do_this<br>
>   else:<br>
>     do_that<br>
<br>
</div><div class="Ih2E3d">> It would be nice if a new object or keyword, say __missing__, was<br>
> introduced as a canonical way to address this common scenario.<br>
<br>
</div>> Thoughts ?<br>
<br>
This has been proposed and shot down before:<br>
<br>
<a href="http://mail.python.org/pipermail/python-dev/2007-May/073439.html" target="_blank">http://mail.python.org/pipermail/python-dev/2007-May/073439.html</a><br>
<br>
The older proposal didn't give __missing__ the special run-time and<br>
compile-time error behaviors, </blockquote><div><br>I agree that it doesn't make sense without special compile/runtime behavior; that would be like adding a second None. <br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
but this actually just makes things<br>
worse. Why complicate the language merely to save a single idiomatic<br>
line of code dealing with a relatively infrequent use-case?</blockquote><div><br>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.<br>
<br>George<br></div></div><br>