[Python-ideas] Raise exception if (not) true
Steven D'Aprano
steve at pearwood.info
Fri Feb 21 05:03:19 CET 2014
On Fri, Feb 21, 2014 at 02:47:17AM +0100, spir wrote:
> On 02/20/2014 10:13 PM, Markus Unterwaditzer wrote:
> >Painting the bikeshed, i'd rather have the syntax
> >
> >assert x > 0, ValueError("x should be positive")
>
> Looks good as well; (but maybe slightly more job to implement, due to
> change of syntax?)
You might not be aware that this piece of code already works in Python
and shouldn't be changed due to backwards compatibility.
py> assert False, ValueError("x should be positive")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError: x should be positive
--
Steven
More information about the Python-ideas
mailing list