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 gpolo
Recipients gpolo
Date 2008-07-24.15:58:57
SpamBayes Score 2.3675874e-07
Marked as misclassified No
Message-id <1216915140.34.0.387873405525.issue3438@psf.upfronthosting.co.za>
In-reply-to
Content
Yesterday I read at a maillist about IDLE being able to use the "with"
statement in python 2.5 without needing to explicitly doing "from
__future__ import with_statement", then today I started tracing the
origin of this. It starts at the use of the InteractiveInterpreter from
the code module (so this report affects any custom shells based on it),
which uses the codeop module to compile lines.

The Compile class of the codeop module, innocently compiles the passed
source with a PyCF_DONT_IMPLY_DEDENT flag by default (I'm not going to
enter in the other details done by Compile). 
This flag is then converted to PyPARSE_DONT_IMPLY_DEDENT (defined at
parsetok.py with a value of 0x0002) by a PARSER_FLAGS macro at
pythonrun.c. Later on the function parsertok at Parser/parsetok.c is
called and it performs this check "if (flags &
PyPARSE_WITH_IS_KEYWORD)", but PyPARSE_WITH_IS_KEYWORD right now has a
value of 0x0003, so this check ends up working for both
PyPARSE_WITH_IS_KEYWORD and PyPARSE_DONT_IMPLY_DEDENT, causing the
with_statement to be enabled if the PyCF_DONT_IMPLY_DEDENT flag is
passed to the compile builtin.

To test this, start the interpreter (python 2.5) and:

>>> a = compile('with open("something") as x: pass\n', '-', 'single', 0x200)
>>> import __future__
>>> a = compile('with open("something") as x: pass\n', '-', 'single',
__future__.with_statement.compiler_flag)

Notice how it works in both cases. 

The patch added is deadly (!) simple (make clean is needed).
History
Date User Action Args
2008-07-24 15:59:00gpolosetspambayes_score: 2.36759e-07 -> 2.3675874e-07
recipients: + gpolo
2008-07-24 15:59:00gpolosetspambayes_score: 2.36759e-07 -> 2.36759e-07
messageid: <1216915140.34.0.387873405525.issue3438@psf.upfronthosting.co.za>
2008-07-24 15:58:59gpololinkissue3438 messages
2008-07-24 15:58:58gpolocreate