<div dir="ltr">There are plenty of PEP-505 threads in the archives, plus the PEP itself. I was only pointing out that the use case in thread might also be solved with an existing proposal*, so I won't derail this thread any further.<div><br></div><div>*There are actually several proposals for short-circuit evaluation, including PEP-531 and PEP-532.<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 28, 2017 at 10:29 AM, Joseph Hackman <span dir="ltr"><<a href="mailto:josephhackman@gmail.com" target="_blank">josephhackman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>I like null coalesce too. :)</div><div id="m_5331884458009691194AppleMailSignature"><br></div><div id="m_5331884458009691194AppleMailSignature">I know that BDFL has said no to ? Before, but was that for the if-then shorthand only? <br></div><div id="m_5331884458009691194AppleMailSignature"><br></div><div id="m_5331884458009691194AppleMailSignature">Perhaps submit a new thread to this list so people can discuss/find?</div><span class="HOEnZb"><font color="#888888"><div id="m_5331884458009691194AppleMailSignature"><br></div><div id="m_5331884458009691194AppleMailSignature">-Joseph</div></font></span><div><div class="h5"><div><br>On Feb 28, 2017, at 10:21 AM, Mark E. Haase <<a href="mailto:mehaase@gmail.com" target="_blank">mehaase@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">This could be solved with a null-coalescing operator, e.g. PEP-505.<div><br></div><div> >>> val = conf.get('setting_name') ?? load_from_db('setting_name')</div><div><br></div><div>The right side isn't evaluated unless the left side is None. It's similar to this:</div><div><br></div><div> >>> val = conf.get('setting_name') or load_from_db('setting_name')</div><div><br></div><div>Except that using "or" would result in any false-y value (0, "", [], etc.) being overridden by the result of `load_from_db(...)`.</div><div><br></div><div>I'm not strongly opposed to "lazy", but I think null-coalescing is easier to reason about.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 28, 2017 at 7:04 AM, Michel Desmoulin <span dir="ltr"><<a href="mailto:desmoulinmichel@gmail.com" target="_blank">desmoulinmichel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The debate on the 'lazy' keyword seems to have settled, but I don't know<br>
if somebody is trying to write a PEP about it.<br>
<br>
Anyway, I was doing something like this the other day:<br>
<br>
conf.get('setting_name', load_from_db('setting_name'))<br>
<br>
And then realized I could save a query not doing the load_from_db() call<br>
most of the time.<br>
<br>
But dict.get didn't accept callable so I couldn't do:<br>
<br>
conf.get('setting_name', lambda key: load_from_db('setting_name'))<br>
<br>
Which is standard practice in a lot of popular Python libs on Pypi.<br>
<br>
Instead I did:<br>
<br>
val = conf.get('setting_name')<br>
if val is None:<br>
val = load_from_db('setting_name')<br>
<br>
Which is way more verbose. It also has a bug if None is a valid<br>
configuration value or if I expect my code to be thread safe.<br>
<br>
It was not a problem for me, but in that case one would even have to do:<br>
<br>
try:<br>
val = conf['setting_name']<br>
except KeyError:<br>
val = load_from_db('setting_name')<br>
<br>
Which is even more verbose.<br>
<br>
I was going to suggest to python-ideas to update the dict.get()<br>
signature to accept a callable, but it would break compatibility with<br>
many code actually getting a callable.<br>
<br>
We could do it for Python 4, but it's far way.<br>
<br>
Instead, I think it's a good example of were 'lazy' could help. You<br>
can't get simpler than:<br>
<br>
conf.get('setting_name', lazy load_from_db('setting_name'))<br>
<br>
<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>______________________________<wbr>_________________</span><br><span>Python-ideas mailing list</span><br><span><a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a></span><br><span><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a></span><br><span>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a></span></div></blockquote></div></div></div></blockquote></div><br></div></div></div>