[Patches] [ python-Patches-548833 ] Optimize code for assert statement

noreply@sourceforge.net noreply@sourceforge.net
Thu, 25 Apr 2002 18:58:34 -0700


Patches item #548833, was opened at 2002-04-25 22:31
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=548833&group_id=5470

Category: Core (C code)
Group: Python 2.3
>Status: Closed
Resolution: Accepted
Priority: 5
Submitted By: Neil Schemenauer (nascheme)
Assigned to: Neil Schemenauer (nascheme)
Summary: Optimize code for assert statement

Initial Comment:
The compiler knows the value of __debug__ so there is
no
need to test it at run time.

----------------------------------------------------------------------

>Comment By: Neil Schemenauer (nascheme)
Date: 2002-04-26 01:58

Message:
Logged In: YES 
user_id=35752

Thanks for the review Guido.  Commited as compile.c 2.242

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-26 00:33

Message:
Logged In: YES 
user_id=6380

OK, you've convinced me.

----------------------------------------------------------------------

Comment By: Neil Schemenauer (nascheme)
Date: 2002-04-26 00:29

Message:
Logged In: YES 
user_id=35752

Assigning to __debug__ doesn't work anyhow.  If the code is
compiled
with -O then the assert operations don't appear in the
bytecode.  The
only use would be to disable asserts by assigning False
__debug__.

Did you forget this thread
http://mail.python.org/pipermail/python-dev/2001-March/013999.html
or am I missing something?

Adding a LOAD_GLOBAL for every assert discourages people
from using
asserts, IMHO.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-26 00:21

Message:
Logged In: YES 
user_id=6380

Hm, this was intentional. You can still set __debug__ (just
import __builtin__).

But I'm not sure if it was ever used or documented.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=548833&group_id=5470