<div dir="ltr">I'd note you can also save 4 characters by writing:<div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>instead if expr is None else expr</div></blockquote><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 9, 2016 at 1:10 PM, David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This idea has come up before.  While I can see the use of it, to me at least that use doesn't feel nearly common enough to warrant dedicated syntax.<div><br></div><div>In many cases, it is a "truthy" value you are looking for rather than `is not None` specifically.  That has a convenient spelling:</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>expr or instead</div></blockquote><br></div><div>If it really is the actual None-ness you are curious about, you need the slightly longer:</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>expr if expr is not None else instead</div></blockquote></div><div><br></div><div>Your example seems to want to fall back to a statement suite rather than a value.  To do that, you'd have to put the suite inside a function such as:</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>def Raise(err):</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>    raise err</div></blockquote><div class="gmail_extra"><br></div><div class="gmail_extra">And use it something like:</div><div class="gmail_extra"><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div class="gmail_extra">self.totalsizeof or Raise(SizeofError(...))</div></div></blockquote><div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, Sep 9, 2016 at 1:01 PM, Arek Bulski <span dir="ltr"><<a href="mailto:arek.bulski@gmail.com" target="_blank">arek.bulski@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div style="font-family:"trebuchet ms",sans-serif">Sometimes I find myself in need of this nice operator that I used back in the days when I was programming in .NET, essentially an expression </div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">>>> expr ?? instead</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">should return expr when it `is not None` and `instead` otherwise. </div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">A piece of code that I just wrote, you can see a use case:</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div><div><font face="trebuchet ms, sans-serif">    def _sizeof(self, context):</font></div><div><font face="trebuchet ms, sans-serif">        if self.totalsizeof is not None:</font></div><div><font face="trebuchet ms, sans-serif">            return self.totalsizeof</font></div><div><font face="trebuchet ms, sans-serif">        else:</font></div><div><font face="trebuchet ms, sans-serif">            raise SizeofError("cannot calculate size")</font></div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">With the oprator it would just be</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div><div><font face="trebuchet ms, sans-serif">    def _sizeof(self, context):</font></div><div><font face="trebuchet ms, sans-serif">        return self.totalsizeof ?? </font><span style="font-family:"trebuchet ms",sans-serif">raise SizeofError("cannot calculate size")</span></div><div style="font-family:"trebuchet ms",sans-serif"><br></div></div></div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div><div><div dir="ltr"><div><div dir="ltr"><div><div><div><font face="'trebuchet ms', sans-serif">pozdrawiam,</font></div><div><font face="'trebuchet ms', sans-serif">Arkadiusz Bulski</font></div><br></div></div></div></div></div></div></div>
</div>
<br></div></div><span class="">______________________________<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></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</font></span></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div></div>