[issue23069] IDLE's F5 Run Module doesn't transfer effects of future import

2020-06-07 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

The only currently active __future__ import is 'annotations'.
https://docs.python.org/3/reference/compound_stmts.html#index-23
The is currently scheduled to be needed indefinitely (until '4.0').

--
versions: +Python 3.10 -Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23069] IDLE's F5 Run Module doesn't transfer effects of future import

2017-06-23 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I am no longer patching 2.7 but there is one __future__ import active in 3.6: 
generator_stop.  If I remember right, there is code that would work without 
future import and fail with it.  In 3.7, it would always fail.

--
assignee:  -> terry.reedy
versions: +Python 3.6, Python 3.7 -Python 2.7, Python 3.4, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23069] IDLE's F5 Run Module doesn't transfer effects of future import

2014-12-19 Thread Terry J. Reedy

Terry J. Reedy added the comment:

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.

--
nosy: +terry.reedy
versions: +Python 3.4, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23069] IDLE's F5 Run Module doesn't transfer effects of future import

2014-12-16 Thread Raymond Hettinger

New submission from Raymond Hettinger:

Future imports in a module aren't transferring to the interactive shell when 
executing Run Module.

Given the file tmp_future.py

$ cat tmp_future.py
from __future__ import division, print_function

print(32 / 5)

Run Python interactively

$ python2.7 -i tmp_future.py 
6.4
>>> 32 / 5  # this works fine!
6.4

But open the file in IDLE and press F5:
---
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>>  RESTART 
>>> 
6.4
>>> print(32 / 5)   # this is broken!
6

Note, the problem may also apply to IDLE Python 3.4 and 3.5 but it won't affect 
this example because the future imports have not effect.

--
components: IDLE
files: tmp_future.py
messages: 232794
nosy: rhettinger
priority: normal
severity: normal
stage: needs patch
status: open
title: IDLE's F5 Run Module doesn't transfer effects of future import
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file37477/tmp_future.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com