[Python-ideas] Raise exception if (not) true

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Feb 20 22:14:39 CET 2014


On 20/02/2014 20:44, spir wrote:
>
> But I would like to be able to add an error type to assertions (in
> addition to the optional message). This is particularly useful for
> people (like me) who systematically check func inputs (for client
> debugging comfort), using assert's. It would be mainly ValueError and
> TypeError.
>
> Example:
>      assert x > 0, "x should be positive", ValueError
> gives:
>      ValueError: x should be positive
> instead of:
>      AssertionError: x should be positive
>
> This is very similar to the proposal above, semantically and
> practically, except we are here just reusing the builtin 'assert'
> instruction with an additional parameter. (Seems backward-compatible to
> me, at first sight, provided the new param comes last. Maybe an issue is
> the hypothetical mention of an error type, without message.)
>
> d

I think this is a dreadful idea.  There's enough confusion for newbies 
now as to when to use assert and when to use raise.  Having a half way 
house like this is to me the worst of both worlds, so let's settle for 
one or the other.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com




More information about the Python-ideas mailing list