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

Ethan Furman ethan at stoneleaf.us
Tue Nov 28 12:23:25 EST 2017


On 11/28/2017 08:03 AM, Ivan Pozdeev via Python-ideas wrote:
> On 28.11.2017 16:36, Nick Coghlan wrote:

>>    it doesn't need to be a statement any more
 >
> Another benefit of a statement vs function is only evaluating the error-related arguments when there's an error

The bulk of any processing in assert (or ensure()) should be the actual check -- if that fails, only state information 
should be included in the exception as anything more complicated runs the risk of also being wrong as the code is now in 
a failed state.  In other words, the "error-related arguments" will often be extremely cheap compared to the test itself.

--
~Ethan~


More information about the Python-ideas mailing list