[Python-ideas] Inline 'raises' expression

Ron Adam rrr at ronadam.com
Mon Aug 25 16:19:02 CEST 2008

Raymond Hettinger wrote:
> From: "Fredrik Johansson" <fredrik.johansson at gmail.com>
>> one could just write
>>    assert 1/0 raises ZeroDivisionError
> +1
> This would be a nice extension to the assertion syntax.


And to do the same thing in other ways isn't as easy as it seems.

Regarding ignoring asserts by -O,  Would it be possible to change asserts 
so they default to off instead of on?  I'd rather have -debug set __debug__ 
to True rather than -0 setting it to False.

Personally I'd like asserts to be part of the testing framework.  ie... 
they are *always skipped* unless possibly a -test or -debug  flag is specified.

Another useful feature would be to specify where asserts sends it's error.

What I'd like to do is to be able to sprinkle asserts throughout my code as 
a way to do simple tests and then possibly ...

    python -debug module.py   ... enable asserts to output to stderr

Or to use plain asserts effectively in unittests and doctests ...

    python -test module.py    ... enamble asserts and run unittests
                                          or doctests for module.

    python -test                  ... run python test suite

Is it too late to go this direction for 3.0, 3.1... ?


More information about the Python-ideas mailing list