Why assert is not a function?

Chris Angelico rosuav at gmail.com
Tue Mar 2 23:28:34 EST 2021


On Wed, Mar 3, 2021 at 2:06 PM Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
> On 3/03/21 12:24 pm, Chris Angelico wrote:
> > if PRODUCTION:
> >      def assert(*a, **kw): pass
> >
> > would work if it were a function :)
>
> But would cost you a useless function call for every assert
> in production mode.
>

A micro-optimization that would almost never actually impact your
code. But considering that I'm willing to keep *the entire check*
active, it's possible I'm slightly biased in favour of debuggability
at the cost of CPU...

ChrisA


More information about the Python-list mailing list