homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author afriesen
Recipients afriesen
Date 2010年04月12日.21:34:04
SpamBayes Score 2.3745825e-09
Marked as misclassified No
Message-id <1271108047.08.0.236449263776.issue8379@psf.upfronthosting.co.za>
In-reply-to
Content
In certain circumstances, "if __debug__" seems to be evaluating its "else" clause even when -O is not specified. This can cause very surprising behavior.
a.zip contains a single file named a/__init__.pyo. It is the compiled form of the following code:
 if __debug__:
 print 'DEBUG'
 else:
 print 'RELEASE'
 if __debug__ == True:
 raise Exception("this is impossible")
pythonbug.py evaluates this script with the following:
 import sys
 sys.path = ['a.zip']
 import a
When using Windows Python 2.6.2 and 2.6.5, running pythonbug.py produces this output:
 RELEASE
 Traceback (most recent call last):
 File "pythonbug.py", line 3, in <module>
 import a
 File "__init__.py", line 8, in <module>
 raise Exception("this is impossible")
 Exception: this is impossible
When -O is passed, the exception is not raised.
My best guess is that the Python bytecode is optimizing the "if __debug__" test away in the produced .pyo, but does not actually affect the value of __debug__ or check more complex expressions involving __debug__.
History
Date User Action Args
2010年04月12日 21:34:07afriesensetrecipients: + afriesen
2010年04月12日 21:34:07afriesensetmessageid: <1271108047.08.0.236449263776.issue8379@psf.upfronthosting.co.za>
2010年04月12日 21:34:05afriesenlinkissue8379 messages
2010年04月12日 21:34:04afriesencreate

AltStyle によって変換されたページ (->オリジナル) /