[Python-ideas] Repurpose `assert' into a general-purpose check

Steven D'Aprano steve at pearwood.info
Wed Jan 17 16:46:06 EST 2018

On Wed, Jan 17, 2018 at 12:19:51PM -0500, Nikolas Vanderhoof wrote:

> I think having a means for such validations separate from assertions would
> be helpful.

What semantics would this "validate" statement have, and how would it be 
different from what we can write now?

    if not condition: raise SomeException(message)

    validate condition, SomeException, message
    # or some other name

Unless it does something better than a simple "if ... raise", there's 
not much point in adding a keyword just to save a few keystrokes.

To justify a keyword, it needs to do something special that a built-in 
function can't do, like delayed evaluation (without wrapping the 
expression in a function).


More information about the Python-ideas mailing list