Issue2029

classification
Title: The codeop.Compile class does not expose compiler flags as expected
Type: Severity: normal
Components: Library Versions: Jython 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, seletz, zyasoft
Priority: normal Keywords:

Created on 2013-03-23.12:08:44 by seletz, last changed 2014-06-19.16:10:46 by zyasoft.

Messages
msg7965 (view) Author: Stefan Eletzhofer (seletz) Date: 2013-03-23.12:08:44
The codeop.Compile class doesn't expose the compiler flags
as expected (as a "flags" attribute).  The flags seem to be
properly implemented in the com.python.core.CompilerFlags
class, but aren't exposed -- they're exposed as _cflags, but
this is a instance of org.python.core.CompilerFlags.

For instance, IPython tries to enable the PyCF_ONLY_AST flag
for it's caching compiler subclass by or-ing it to an expected
`flags` attribute.

The bit values of the constants implemented in com.python.core.CompilerFlags seem to match the CPython
implementation at a first glance.
msg7967 (view) Author: Stefan Eletzhofer (seletz) Date: 2013-03-23.13:19:21
Maybe something like this could help:

--- codeop.py.orig	2013-03-23 14:06:50.000000000 +0100
+++ codeop.py	2013-03-23 14:13:21.000000000 +0100
@@ -87,17 +87,33 @@
     symbol = CompileMode.getMode(symbol)
     return Py.compile_command_flags(source,filename,symbol,Py.getCompilerFlags(),0)

+class CompilerFlagsWrapper(object):
+    def __init__(self):
+        self._flags = CompilerFlags()
+
+    def __get__(self, f, tp):
+        return self._flags.toBits()
+
+    def __set__(self, f):
+        self._flags = CompilerFlags(f)
+
+    def __or__(self, f):
+        self._flags = self._flags.combine(f)
+
 class Compile:
     """Instances of this class behave much like the built-in compile
     function, but if one is used to compile text containing a future
     statement, it "remembers" and compiles all subsequent program texts
     with the statement in force."""
+
     def __init__(self):
-        self._cflags = CompilerFlags()
+        pass
+
+    flags = CompilerFlagsWrapper()

     def __call__(self, source, filename, symbol):
         symbol = CompileMode.getMode(symbol)
-        return Py.compile_flags(source, filename, symbol, self._cflags)
+        return Py.compile_flags(source, filename, symbol, CompilerFlags(self.flags))

 class CommandCompiler:
     """Instances of this class have __call__ methods identical in
@@ -106,8 +122,10 @@
     the instance 'remembers' and compiles all subsequent program texts
     with the statement in force."""

-    def __init__(self,):
-        self._cflags = CompilerFlags()
+    def __init__(self):
+        pass
+
+    flags = CompilerFlagsWrapper()

     def __call__(self, source, filename="<input>", symbol="single"):
         r"""Compile a command and determine whether it is incomplete.
@@ -131,4 +149,4 @@
         if symbol not in ['single','eval']:
             raise ValueError,"symbol arg must be either single or eval"
         symbol = CompileMode.getMode(symbol)
-        return Py.compile_command_flags(source,filename,symbol,self._cflags,0)
+        return Py.compile_command_flags(source,filename,symbol,CompilerFlags(self.flags),0)
msg8753 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.16:10:46
Target beta 4
History
Date User Action Args
2014-06-19 16:10:46zyasoftsetnosy: + zyasoft
messages: + msg8753
2013-03-23 20:13:05fwierzbickisetpriority: normal
nosy: + fwierzbicki
2013-03-23 13:19:22seletzsetmessages: + msg7967
2013-03-23 12:08:44seletzcreate