[Python-ideas] Inline 'raises' expression

Giampaolo Rodola' gnewsg at gmail.com
Wed Aug 27 14:50:54 CEST 2008


On 24 Ago, 12:43, "Fredrik Johansson" <fredrik.johans... at gmail.com>
wrote:
> Hi,
>
> It happens that I'm just interested in whether an expression raises an
> exception, not the return value. This might look something like
>
>     try:
>         check_status()
>     except IOError:
>         cleanup()
>
> which could be written more simply as
>
>     if check_status() raises IOError:
>         cleanup()
>
> Also, instead of the inconvenient
>
>     self.assertRaises(ZeroDivisionError, lambda: 1/0)
>
> one could just write
>
>     assert 1/0 raises ZeroDivisionError
>
> Something like this would especially be useful for those of us who
> aren't fans of the unittest framework. Alternatively, just the
> assert--raises form could be permitted.
>
> Thoughts?
>
> Fredrik
> _______________________________________________
> Python-ideas mailing list
> Python-id... at python.orghttp://mail.python.org/mailman/listinfo/python-ideas

+1, I really like it.


--- Giampaolo
http://code.google.com/p/pyftpdlib/



More information about the Python-ideas mailing list