<div class="gmail_quote">On Wed, Jul 13, 2011 at 8:23 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Eric Snow wrote:<br></div><div>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
A New Solution<br>
---------------<br>
<br>
Provide a builtin version of a Deferred singleton, like None or<br>
NotImplemented. When resolving arguments for a call, if an argument<br>
is this Deferred object, replace it with the default argument for that<br>
parameter on the called function, if there is one. If there isn't,<br>
act as though that argument was not passed at all.<br>
</blockquote>
<br></div>
I don't believe that should be a public object. If it's public, people will say "Yes, but what do you do if you want the default to actually be the Deferred singleton?" It's the None-as-sentinel problem all over again... sometimes you want None to stand in for no value, and sometimes you want it to be a first class value.</blockquote>
<div><br></div><div>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:</div><div><br></div><div> SENTINEL = object() # Guaranteed to be unique and not None.</div>
<div> </div><div> def f(arg=SENTINEL):</div><div> if arg is SENTINEL:</div><div> arg = 'foo'</div><div> x(arg)</div><div><br></div><div>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?</div>
</div>