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 terry.reedy
Recipients rhettinger, terry.reedy
Date 2014-12-19.23:48:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1419032936.93.0.700262890191.issue23069@psf.upfronthosting.co.za>
In-reply-to
Content
I agree that this is broken.  I verified that the following works in 2.7.9

>>> from __future__ import division, print_function
>>> 32 / 5
6.4
>>> print(2,3,sep='**')
2**3

#13296 was about self.compile.compiler.flags (in ModifiedInterpreter, which inherits .compile... from code.InteractiveInterpreter) not being *reset* to their original values upon Shell restart.  They are now.

This issue is about the same flags not being *set* by Run Module.  This will be tricky to fix, but I think it can be done using the previous flag issue as a hint.

self.compile (in InteractiveInterpreter) = codeop.CommandCompiler().
The docstring for the class says
    """Instances of this class have __call__ methods identical in
    signature to compile_command; the difference is that if the
    instance compiles program text containing a __future__ statement,
    the instance 'remembers' and compiles all subsequent program texts
    with the statement in force."""
The __call__ method handles partial or complete single statements.

Run -> Run Module F5, on the other hand,  is handled by the ScriptBindind.py extension.  ScriptBinding.run_module_event calls .checksyntax().  The latter calls builtin compile(), independent of the shell interpreter.compile, without saving the compile flags.

To save the compile flags, we could use codeop.Compile.__call__, which calls builtin compile() and then extracts and saves future compile flags from the resulting code object using constants defined in the module.

The next issue is timing.  The shell restarts (and resets its flags) only after the file passes compile and tabnanny steps.  After the restart, it should be possible to update the shell compile flags with any future flags saved by the Compile() instance.

I have skipped over some details (including the lack of tests for Run Module), but I *think* that the above outlines a safe solution.  As for 3.x, there are changes in 3.4 ScriptBinding.py, but the essential points for this issue seem the same.  3.x should be patched also to be ready for future __future__ imports.
History
Date User Action Args
2014-12-19 23:48:56terry.reedysetrecipients: + terry.reedy, rhettinger
2014-12-19 23:48:56terry.reedysetmessageid: <1419032936.93.0.700262890191.issue23069@psf.upfronthosting.co.za>
2014-12-19 23:48:56terry.reedylinkissue23069 messages
2014-12-19 23:48:56terry.reedycreate