[Python-ideas] Another use case for the 'lazy' (aka 'delayed') keyword
desmoulinmichel at gmail.com
Tue Feb 28 10:28:34 EST 2017
Only if "None" is not a proper value from .get().
And this doest solve the problems with more general callbacks that are
not trying to get a value (cf Django lazy_gettext).
Besides, "??" does not exist yet for Python, so let's counter the
argument for lazy with the potential benefits of something we don't have
A proposal is already hard enough to defenD on Python-ideas :)
Le 28/02/2017 à 16:21, Mark E. Haase a écrit :
> This could be solved with a null-coalescing operator, e.g. PEP-505.
> >>> val = conf.get('setting_name') ?? load_from_db('setting_name')
> The right side isn't evaluated unless the left side is None. It's
> similar to this:
> >>> val = conf.get('setting_name') or load_from_db('setting_name')
> Except that using "or" would result in any false-y value (0, "", ,
> etc.) being overridden by the result of `load_from_db(...)`.
> I'm not strongly opposed to "lazy", but I think null-coalescing is
> easier to reason about.
More information about the Python-ideas