<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sat, Aug 6, 2016 at 10:13 PM Terry Reedy <<a href="mailto:tjreedy@udel.edu">tjreedy@udel.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 8/6/2016 8:57 PM, Michael Selik wrote:<br>> On Sat, Aug 6, 2016, 7:24 PM אלעזר<br>
> <<a href="mailto:elazarg@gmail.com" target="_blank">elazarg@gmail.com</a><br>
> <mailto:<a href="mailto:elazarg@gmail.com" target="_blank">elazarg@gmail.com</a>>> wrote:<br>>     The raise statement cannot be used as an expression, even though<br>
>     there is no theoretical reason for it not to. I don't see any<br>
>     practical reason either - except the fact that it requires changing<br>
>     the syntax.<br>
><br>
>     I have found this idea mentioned by Anthony Lee in a thread from<br>
>     2014, regarding "or<br>
>     raise", <a href="https://mail.python.org/pipermail/python-ideas/2014-November/029921.html" rel="noreferrer" target="_blank">https://mail.python.org/pipermail/python-ideas/2014-November/029921.html</a>. But there<br>
>     is nothing against the idea there.<br>
><br>
>     Yes, it could easily be implemented using a function, but this seems<br>
>     to be an argument against *augmenting* the language, not against<br>
>     *changing* it. Moreover, this function will have uglier name, since<br>
>     `raise` is taken. (It could have been the other way around -<br>
>     omitting the statement entirely, leaving only a built in function<br>
>     `raise()`. I'm not suggesting that, of course)<br>
><br>
><br>
> Luckily, "throw" is available for you.<br>
><br>
> def throw(exception):<br>
>     raise exception<br>
<br>
Nice.  This makes the 'or raise' construct available to any who like it<br>
in all versions.  There is precedent for this name in generator.throw.<br></blockquote><div><br></div><div>I suppose it should really be more like</div><div><div>In [1]: def throw(exception=None, *, cause=None):</div><div>    ...:     if exception is None:</div><div>    ...:         raise</div><div>    ...:     if cause is None:</div><div>    ...:         raise exception</div><div>    ...:     raise exception from cause</div></div><div><br></div><div><br></div><div>I'm not sure if I like the use in a shortcut expression. Too easy to accidentally use ``or`` when you mean ``and`` and vice versa.</div><div><br></div><div>    False or throw(RuntimeError('you shoulda been True to me'))</div><div>    True and throw(RuntimeError('I knew it was you, Fredo.'))</div></div></div>