Re: Default value lost in binding.Obtain()
PJ Eby <pje-Wh6+Hckhi6HFNGf7iClzIwC/[email protected]> Tue, 29 Sep 2015 18:53:07 -0400
| Newsgroups | gmane.comp.python.peak |
|---|---|
| Message-ID | <CALeMXf7r-97fyJ0akJhvA7=ViwMS5LwR8pCWtP40PRTE7HS=6A@mail.gmail.com> |
Thanks for reporting the problem. Unfortunately your patch will mask any other sort of name error, including one that happens indirectly as a side effect of the lookup. I think the correct fix is going to be to change the nameNotFound() method of config.IConfigurationRoot to include a default (defaulting to NOT_GIVEN), and have acquireComponent() take a default and pass it along to nameNotFound(). This would handle the case of a direct lookup failing by returning the default, but still raise an error for any other part of the process getting a naming error. On Tue, Sep 29, 2015 at 9:03 AM, Alexey Smishlayev <[email protected]> wrote: > Hello! > > Today, fiddling with the binding.Obtain() I noticed that the default value > gets lost. > > In my application, I have a component tree and I want an attribute to be > defined in any component in that tree, so I created binding: > >> callback = binding.Obtain("callbackFunction", default=lambda arg: >> None) >> > > So, in case that no component defines a callbackFunction, the lambda > function would be used as a fallback. > Unfortunately, "default" option is ignored unless target name contains > slashes (e.g. "/callbackFunction", "./callBackFunction", > "../callbackFunction") > > I went to the peak/binding/components.py trying to fix it and propose the > attached patch. > The problem is that default value was not propagated to the > acquireComponent() call, so an exception occurred. > > > Best regards, > Alexey Smishlayev > > _______________________________________________ > PEAK mailing list > [email protected] > http://www.eby-sarna.com/mailman/listinfo/peak