[Python-ideas] __missing__ object/keyword
Michael
fuzzyman at gmail.com
Sat Nov 8 12:36:29 CET 2008
This seems to be a solution in search of a problem. If you handle
sentinel default values early in a function then they are rarely
problematic.
Michael Foord
http://www.ironpythoninaction.com
On 8 Nov 2008, at 05:37, "Bruce Leban" <bruce at leapyear.org> wrote:
> The problem with using a value like None as some have proposed is
> that None may be a valid parameter value. Thus the only safe value
> is a special value like a throwaway object. There are numerous
> problems with this including that it's not safe: I might not check
> for the missing value in some place and end up passing the throwaway
> object to another function which then passes it as one of the
> optional values.
>
> 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.
>
> 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.
>
> I agree it would be nice to have a way to check whether a variable
> is unbound without writing a multi-line try/except, but I think that
> can be discussed as a different issue.
>
> --- Bruce
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
More information about the Python-ideas
mailing list