Marc-Andre, I must agree that the current state of assertions with "-O" and "-OO" is difficult to impossible to change.
Perhaps I'm looking for an: *invariant* cond: etc Regards, On Sat, Sep 11, 2021 at 11:00 AM Marc-Andre Lemburg <m...@egenix.com> wrote: > On 11.09.2021 15:17, Juancarlo Añez wrote: > > Of course, none of this will make sense to programmers with a strong > belief that > > assertions must always be turned off in production runs. > > You seem to be missing that the Python optimize mode turns off > all code which is related to debugging (__debug__ is set to False, > the compiler doesn't generate code for "if __debug__: ..." statements). > > assert is just one of the instances where this happens: > > > https://docs.python.org/3/reference/simple_stmts.html#grammar-token-assert-stmt > > asserts are meant to help find bugs in programs, not check for > user input errors. They document assumptions a programmer has made > when writing the code, which are then tested with a test suite to > make sure the assumptions hold as invariants of the application. > > For anything which can go wrong at production run-time, please use > normal if-statement checks and raise appropriate exceptions. > > Using assert in such cases is dangerous and can render your > application broken, while everything appears to be running fine > when testing. > > Unlike regular if-statement checks, asserts are meant to never > trigger an exception in production code -- which is why they > are removed with -O. > > This is not about whether or not to use -O in production environments, > it's about preventing user input exceptions from going unnoticed > when code is run with -O (e.g. the deployment team or a user > decided to always use -O in production). > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Experts (#1, Sep 11 2021) > >>> Python Projects, Coaching and Support ... https://www.egenix.com/ > >>> Python Product Development ... https://consulting.egenix.com/ > ________________________________________________________________________ > > ::: We implement business ideas - efficiently in both time and costs ::: > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > https://www.egenix.com/company/contact/ > https://www.malemburg.com/ > > -- Juancarlo *Añez*
_______________________________________________ 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/TEV4XSLWV4IU3TD2KDDVZEKJYPFUDELS/ Code of Conduct: http://python.org/psf/codeofconduct/