On Sun, May 24, 2020 at 12:55 PM Chris Angelico <ros...@gmail.com> wrote:
> > And it isn't entirely correct, because now None isn't a valid > parameter. Which is indeed, an extremely common use case :-) > It's an extremely common idiom right up until it doesn't > work, and you need: > > _SENTINEL = object() > def fun(..., option=_SENTINEL): > if option is _SENTINEL: > option = something_else > I've thought to a while that there should be a more "standard" way to so this: A NOT_SPECIFIED singleton in builtins would be pretty clear. (though I'd like to find a shorter spelling for that) BTW, though I do find it tedious to write the: if option is SOME_SENTINEL: option = something ... It's not always the case that it's a simple setting of the value to a empty mutable -- sometimes there's some more complexity there. Which is why I kind of like that it's explicit. But if we did make it simpler, I like the idea of providing a factory function, so it would be possible to do more complex things than a simple empty container of some sort. Though that factory wouldn't have access to the full function namespace, so maybe not that flexible. -CHB -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DFYCRQHTBOB264WBLVZUPGCJS7CKVWDA/ Code of Conduct: http://python.org/psf/codeofconduct/