[Python-ideas] Make "raise" an expression

Terry Reedy tjreedy at udel.edu
Sat Aug 6 22:12:57 EDT 2016


On 8/6/2016 8:57 PM, Michael Selik wrote:
>
>
> On Sat, Aug 6, 2016, 7:24 PM אלעזר
> <elazarg at gmail.com
> <mailto:elazarg at gmail.com>> wrote:
>
>     The raise statement cannot be used as an expression, even though
>     there is no theoretical reason for it not to. I don't see any
>     practical reason either - except the fact that it requires changing
>     the syntax.
>
>     I have found this idea mentioned by Anthony Lee in a thread from
>     2014, regarding "or
>     raise", https://mail.python.org/pipermail/python-ideas/2014-November/029921.html. But there
>     is nothing against the idea there.
>
>     Yes, it could easily be implemented using a function, but this seems
>     to be an argument against *augmenting* the language, not against
>     *changing* it. Moreover, this function will have uglier name, since
>     `raise` is taken. (It could have been the other way around -
>     omitting the statement entirely, leaving only a built in function
>     `raise()`. I'm not suggesting that, of course)
>
>
> Luckily, "throw" is available for you.
>
> def throw(exception):
>     raise exception

Nice.  This makes the 'or raise' construct available to any who like it 
in all versions.  There is precedent for this name in generator.throw.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list