Terry J. Reedy added the comment:

Duplicate #28581 has a autosave patch in the initial post, which points out 
that "We are often required to copy code from various sites say some tutorial 
or code samples which are good for one time usage."

It prompted me to think more about the idea to 'add a mechanism to truly run 
without saving [to disk]', which I mentioned in my first post above.  To run 
editor code, IDLE retrieves the code from the Text widget as a single strings; 
runs compile(code, 'filename', 'exec'), ships the code object to the user 
process, and runs exec(code, fakemain).  (I understand this much better now 
than 3 years ago.)  The only use of the disk copy is for tracebacks.  But is it 
*needed*?  I believe not.  Here is standard interactive Python (3.5.2):

>>> def f():
        1/0
        
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in f
ZeroDivisionError: division by zero
>>>

Here is the same traceback in IDLE's Shell:

Traceback (most recent call last):
  File "<pyshell#40>", line 1, in <module>
    f()
  File "<pyshell#39>", line 2, in f
    1/0
ZeroDivisionError: division by zero

IDLE has filled in the missing lines from Shell's text.  I have not yet tracked 
where this is done (in pyshell.py, I believe), but I presume it could do the 
same for Untitled editor windows.  For this to work, the window titles should 
be Untitled-0, Untitled-1, ... .  The specific name used in the compile call 
would appear in the traceback, to be used to lookup the window the code came 
from.

With the ability to run the whole buffer without saving, it would be easy to 
run a selection.  (There have been multiple requests for this.)

IDLE already asks about saving when one tried to close a window with unsaved 
text, so there is no need to force saving when running for this purpose.

----------
versions: +Python 3.6, Python 3.7 -Python 2.7, Python 3.3, Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19042>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to