I am not sure if I fully understand the proposal then. NoDefault would be special syntax so that this would be disallowed:
f(NoDefault) but this would be allowed: def f(x=NoDefault): ... and also this: x is NoDefault So this would seem to require an exhaustive list of syntactic contexts in which NoDefault is allowed. I mean, can I do: x = NoDefault ? I observe that I can always get to the underlying NoDefault object in this way: (lambda x=NoDefault:x)() So what happens if I do: f((lambda x=NoDefault:x)()) ? Stephan 2017-03-02 12:15 GMT+01:00 M.-A. Lemburg <m...@egenix.com>: > On 02.03.2017 11:22, Stephan Houben wrote: > > In cases like this I would recommend creating the sentinel yourself: > > > > NoDefault = object() > > > > def get(store, key, default=NoDefault): > > if default is NoDefault: > > # do something > > > > You can arrange to not export NoDefault so that the client code cannot > even > > access > > the sentinel value. > > Yes, I know... I've been using the mxTools NotGiven since 1998. > > > This is strictly preferable over having yet another global > > value meaning "no value", since that just moves the goal posts: > > clients will complain they cannot pass in a default=NoDefault and get > back > > NoDefault. > > Not really. NoDefault would mean: no value provided, not that > you don't want a value. As a result, passing NoDefault would > not be allowed, since then you'd be providing a value :-) > > > Stephan > > > > > > 2017-03-02 11:04 GMT+01:00 M.-A. Lemburg <m...@egenix.com>: > > > >> On 02.03.2017 10:06, Serhiy Storchaka wrote: > >>> On 02.03.17 10:36, M.-A. Lemburg wrote: > >>>> Why a new syntax ? Can't we just have a pre-defined sentinel > >>>> singleton NoDefault and use that throughout the code (and also > >>>> special case it in argument parsing/handling)? > >>>> > >>>> def get(store, key, default=NoDefault): > >>>> if store.exists(key): > >>>> return store.retrieve(key) > >>>> ... > >>> > >>> This means adding a new syntax. NoDefault should be a keyword (we can > >>> reuse existing keyword couldn't be used in expression), and it should > be > >>> accepted only in the specific context of declaring function parameter. > >> > >> This is not new syntax, nor is it a keyword. It's only a > >> new singleton and it is well usable outside of function > >> declarations as well, e.g. for class attributes which are > >> not yet initialized (and which can accept None as value). > >> > >> The only special casing would be in function call > >> parameter parsing to signal errors when the parameter > >> is used as keyword parameter. > >> > >> -- > >> Marc-Andre Lemburg > >> eGenix.com > >> > >> Professional Python Services directly from the Experts (#1, Mar 02 2017) > >>>>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ > >>>>> Python Database Interfaces ... http://products.egenix.com/ > >>>>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ > >> ____________________________________________________________ > ____________ > >> > >> ::: We implement business ideas - efficiently in both time and costs ::: > >> > >> eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > >> D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > >> Registered at Amtsgericht Duesseldorf: HRB 46611 > >> http://www.egenix.com/company/contact/ > >> http://www.malemburg.com/ > >> > >> _______________________________________________ > >> Python-ideas mailing list > >> Python-ideas@python.org > >> https://mail.python.org/mailman/listinfo/python-ideas > >> Code of Conduct: http://python.org/psf/codeofconduct/ > >> > > > > > > > > _______________________________________________ > > Python-ideas mailing list > > Python-ideas@python.org > > https://mail.python.org/mailman/listinfo/python-ideas > > Code of Conduct: http://python.org/psf/codeofconduct/ > > > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Experts (#1, Mar 02 2017) > >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ > >>> Python Database Interfaces ... http://products.egenix.com/ > >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ > ________________________________________________________________________ > > ::: We implement business ideas - efficiently in both time and costs ::: > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > http://www.malemburg.com/ > >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/