Why assert is not a function?

Grant Edwards grant.b.edwards at gmail.com
Wed Mar 3 11:50:31 EST 2021


On 2021-03-03, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Mar 4, 2021 at 1:40 AM Grant Edwards <grant.b.edwards at gmail.com> wrote:
>
>> 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.

Good point. I had forgotten about having the expression available in
the exception output. That's definitly valuable.




More information about the Python-list mailing list