New submission from Guilherme Polo <[EMAIL PROTECTED]>: 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). ---------- components: Interpreter Core files: new_PyPARSE_WITH_IS_KEYWORD.diff keywords: patch messages: 70210 nosy: gpolo severity: normal status: open title: PyCF_DONT_IMPLY_DEDENT can be used to activate the with statement versions: Python 2.5 Added file: http://bugs.python.org/file10968/new_PyPARSE_WITH_IS_KEYWORD.diff _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3438> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com