[Python-ideas] "or raise" syntax
Javier Dehesa
javidcf at gmail.com
Thu Oct 30 16:03:41 CET 2014
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
More information about the Python-ideas
mailing list