On Sun, May 17, 2020 at 09:04:50PM -0000, Alex Hall wrote:

> Some people (like myself, or the coworkers of [this 
> person](https://mail.python.org/archives/list/python-ideas@python.org/thread/PLXOXKACKGXN4ZKISDVXLKMFIETWTF63/))
>  
> just like to use asserts as a convenient way to check things. We don't 
> want asserts to ever be turned off. 

That's not your choice. The choice to turn assertions off belongs to the 
person running the code, not you. If you are not prepared for the user 
to turn assertions off, then your code is buggy.


> Maybe there could be some kind of 
> compiler directive which means "in this file, even with -O, keep the 
> asserts". Maybe the line `assert __debug__`?

Indeed this feature already exists. It's written as:

    if condition: raise Exception

and you can control when it is enabled or disabled, the end user 
can't change that. Even better, you can use the correct, meaningful 
exception instead of using the wrong, misleading exception.

`assert` is for assertions, not error checking. If you don't want the 
semantics of an assertion, then don't use `assert`.


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LLD3SBBMQQHY7PQPZHN2JRCIH3UDIJTH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to