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

Steven D'Aprano steve at pearwood.info
Tue Nov 28 00:59:56 EST 2017

On Tue, Nov 28, 2017 at 07:35:45AM +0300, Ivan Pozdeev via Python-ideas wrote:

> Actually, the way I'm using them,
>     assert condition, "error message", type
> would probably be the most expressive way.

I disagree that is expressive -- I call it *misleading*. I see something 
which looks like an assertion (that is, a checked comment, a contract, a 
check on an internal piece of logic etc) but it is actually being used 
as a test.

> I can do anything in any Turing-complete language without any changes to 
> the language. That's no reason to never change anything, is it.

"We can change this" is not a reason to change this. There needs to be a 
*good* reason to change, and you have given no good reasons for this 

> The rationale basically is:
> * As it was intended, the statement has no practical use -- basically a 
> rudiment, due to disappear eventually

Nonsense. I make extensive use of assert as a way of checking 
assertions, and I will fight tooth and nail against any proposal to 
either remove it or to misuse it for public input tests instead of 

> * It can instead be reused as syntax sugar to cover a very common use case

There is no need for such syntactic sugar. It would be harmful 
to use assert for something which is not an assertion.


More information about the Python-ideas mailing list