Why assert is not a function?

Grant Edwards grant.b.edwards at gmail.com
Tue Mar 2 21:05:02 EST 2021


On 2021-03-02, Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, Mar 3, 2021 at 10:22 AM Mirko via Python-list><python-list at 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.

--
Grant





More information about the Python-list mailing list