Issue2029

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

Created on 2013-03-23.12:08:44 by seletz, last changed 2018-03-07.19:07:17 by jeff.allen.

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
msg9419 (view) Author: Jim Baker (zyasoft) Date: 2015-01-17.18:40:16
Missed in the final triage, let's see if this can get fixed
History
Date User Action Args
2018-03-07 19:07:17jeff.allensetmilestone: Jython 2.7.2 ->
2017-09-25 03:36:50zyasoftsetresolution: remind
2015-12-29 23:45:22zyasoftsetmilestone: Jython 2.7.1 -> Jython 2.7.2
2015-04-15 20:41:29zyasoftsetassignee: zyasoft ->
2015-04-15 20:41:21zyasoftsetmilestone: Jython 2.7.1
2015-01-17 18:40:16zyasoftsetpriority: normal -> high
assignee: zyasoft
messages: + msg9419
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