On Thu, Mar 4, 2021 at 1:40 AM Grant Edwards <grant.b.edwa...@gmail.com> wrote: > > On 2021-03-02, Chris Angelico <ros...@gmail.com> wrote: > > On Wed, Mar 3, 2021 at 10:22 AM Mirko via > > Python-list><python-list@python.org> wrote: > > > >> In production code you don't want any asserts, but logging. Having > >> "assert" being a function would make it much harder to get rid of > >> it in production code. > > > > Really? > > > > if PRODUCTION: > > def assert(*a, **kw): pass > > > > would work if it were a function :) > > Wouldn't that still evaluate all of the arguments? You get rid of the > value of the assert, but retain almost all of the cost. > > I thought the entire point of asser being a keyword was so that if you > disable asserts then they go away completely: the arguments aren't > even evaluated. >
It depends on what the point of "removing the assertions" is, but yes, that will indeed still evaluate the arguments. IMO the cost of running assertions isn't that high compared to the value of keeping them (which is why I never run -O), and the performance argument is a weak one compared to the much stronger value of having the actual failing expression available in the exception report. ChrisA -- https://mail.python.org/mailman/listinfo/python-list