
On Sat, Nov 8, 2008 at 12:37 AM, Bruce Leban <bruce@leapyear.org> wrote: There *is* one guaranteed way of ensuring that I can't use a variable's
value: leaving it unbound. That is, to support this, we would add a new syntax something like what George proposed with slightly different semantics:
def foo(x, y=__unbound__):
where if y is omitted from the call, then y is unbound. This is slightly different than what would happen if y were left out of the parameter list as in that case, y could reference a global of the same name. In this case, y can only reference an unbound local.
No other changes are required to use this. If I don't check whether or not y is bound, then I'll get a NameError when I try to use it, just as with any other unbound variable.
I like that, it's more straightforward than checking for identity with a __missing__ pseudo-object. if this was to be accepted, checking whether a name is bound would be more common than now, so it might be worthwhile considering a new isbound('var') builtin as a more explicit (and perhaps faster) alternative of "if 'var' in locals()". If this proposal were to be seriously considered, there are of course
alternative syntaxes that could be considered, like using missing, __missing__ or def foo(x, ?y) but that's getting ahead.
+1 for the alternative syntax, reads much better and it's at least as intuitive as *args and **kwds. George