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.

classification
Title: PyCF_DONT_IMPLY_DEDENT can be used to activate the with statement
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: gpolo, rdemetrescu
Priority: normal Keywords: patch

Created on 2008-07-24 15:58 by gpolo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
new_PyPARSE_WITH_IS_KEYWORD.diff gpolo, 2008-07-24 15:58
Messages (3)
msg70210 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-07-24 15:58
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).
msg70211 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-07-24 16:01
"This flag is then converted to PyPARSE_DONT_IMPLY_DEDENT (defined at
parsetok.py with a value of 0x0002"

Sorry, it is defined at "parsetok.h" of course.
msg91391 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-08-06 22:56
This isn't going to happen, closing.
History
Date User Action Args
2022-04-11 14:56:36adminsetgithub: 47688
2009-08-06 22:56:53gpolosetstatus: open -> closed
resolution: wont fix
messages: + msg91391
2008-07-24 17:23:44rdemetrescusetnosy: + rdemetrescu
2008-07-24 16:01:37gpolosetmessages: + msg70211
2008-07-24 15:58:59gpolocreate