[Python-ideas] parameter omit
Jim Jewett
jimjjewett at gmail.com
Sat May 12 18:35:54 CEST 2007
On 5/11/07, Aaron Brady <castironpi at comcast.net> wrote:
> And while I'm at it and thinking clearly, with cool weather and open doors,
> the basic problem here, underlying and distilled, is that None is serving
> double-duty.
Yes. When None appears in a parameter list (or an argument list, at
the calling site), it might really be a sentinel for something else,
and that is a wart.
> You could always require all parameter defaults to equal `None'. But since
> they're not, take this.
> DefaultArg = object()
Yes; this is used when None actually is a valid and meaningful value.
I don't see a good way to *always* use this idiom though, because
(1) If DefaultArg is a pre-existing object, then there will be times
when it is valid and meaningful data -- such as when introspecting.
(2) Creating it afresh is a bit of boilerplate that we wouldn't want
to require when it isn't really needed.
sentinel=object()
def f(val=sentinel):
if val is sentinel:
And note that the creation can't be inline, such as
def f(val=object()):
or there wouldn't be any good way to test for it. Adding a keyword to do that
def f(val=object()):
if defaulted val:
would probably be a good idea. (I don't think it would get used often
enough to justify the costs of a change, but there would be a clear
benefit to include in the cost-benefit calculations.)
-jJ
More information about the Python-ideas
mailing list