
This happens to me with some frequency: result = f(args) if not result: # of "if result is None:" raise Exception(...) What if I could just say? result = f(args) or raise Exception(...) I think that's pretty idiomatic. What's more, this would give you a shorter syntax for things like: if x <= y: raise Exception(...) Which you could write simply as: x > y or raise Exception(...) Effectively covering the use case of this proposal http://article.gmane.org/gmane.comp.python.ideas/26005/ Has this ever been considered? Javier

On 10/30/2014 11:13 AM, Ethan Furman wrote:
No need to pass exception class and message separately instead of an exception instance. def raiser(exc): raise exc print(1 or raiser(ValueError('null value'))) print(0 or raiser(ValueError('null value')))
It does add another line to the trackback, but this is pretty minor. -- Terry Jan Reedy

If anything, a better idea would be to make "raise [... [from ...]]" an expression (possibly requiring parentheses, à la yield), thus allowing it to be put in constructs such as the one suggested, but also in lambda expressions. Of course, the value of the expression doesn't have to be specified (the assignment target stays unbound, causing a NameError if we somehow catch the exception and later refer to the assignment target). 2014-10-30 11:45 GMT-07:00 Terry Reedy <tjreedy@udel.edu>:

On 10/30/2014 11:13 AM, Ethan Furman wrote:
No need to pass exception class and message separately instead of an exception instance. def raiser(exc): raise exc print(1 or raiser(ValueError('null value'))) print(0 or raiser(ValueError('null value')))
It does add another line to the trackback, but this is pretty minor. -- Terry Jan Reedy

If anything, a better idea would be to make "raise [... [from ...]]" an expression (possibly requiring parentheses, à la yield), thus allowing it to be put in constructs such as the one suggested, but also in lambda expressions. Of course, the value of the expression doesn't have to be specified (the assignment target stays unbound, causing a NameError if we somehow catch the exception and later refer to the assignment target). 2014-10-30 11:45 GMT-07:00 Terry Reedy <tjreedy@udel.edu>:
participants (4)
-
Antony Lee
-
Ethan Furman
-
Javier Dehesa
-
Terry Reedy