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.

Title: IDLE: unrequested pasting into Shell after restart
Type: behavior Stage: needs patch
Components: IDLE Versions: Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: cheryl.sabella, epaine, rhettinger, taleinat, terry.reedy
Priority: normal Keywords:

Created on 2018-12-12 02:32 by terry.reedy, last changed 2022-04-11 14:59 by admin.

Messages (6)
msg331668 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-12-12 02:32
IDLE very occasionally (frequency much less than .01), and AFAIK hapzardly, pastes previous shell output after I enter something at the prompt after a restart.  Not fatal but definitly annoying.  When it happened today, I decided to open this issue to start accumulating information that might point at where to start.  (content likely not relevant)

import inspect
class A:

Shell copy:
OSError: could not find class definition
======================== RESTART: F:\Python\a\ ========================
class A:

>>> 1/0======================== RESTART: F:\Python\a\ ========================
class A:
SyntaxError: invalid syntax
>>> 1/0
Traceback (most recent call last):

The paste, after '1/0', is the restart line and the first two lines of output (but not the last two).  It mixes text from IDLE and from the program, so it is not an echo from the run process).  It is colored as if typed in: 'class' and 'pass' are keyword colored, the  I believe I hit ENTER  and got the paste instead of the exception.  I hit Entere after the paste to get the SyntaxError and a clean prompt.  Then I reentered 1/0.

I did more or less the same thing about 5 times without a repeat of the problem.

Possible factors:
exception before restart (probably not relevant).
restart, prompt, and entry (I believe these are essential elements).
running a file (I seldom restart other wise).
hitting return

Included Content:
restart line (I am pretty sure pasted text does not always include this).
output from before the restart (ever?).
output from after the restart (if always, must have run a file).

Raymond, I believe you have seen this on Mac.  Tal or Sheryl, how about linux?  Anyone, more details on other examples are needed to know what is constant and what is incidental.
msg331723 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-12-13 00:29
I don't believe I've seen this happen, but I'll watch for it.  One thing that I noticed while trying to recreate it is that I can press F5 on the Shell window even though there isn't a Run menu.  Maybe the issue is somehow related using shortcuts that aren't defined for Shell.
msg331737 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-12-13 03:30
Thank you for the report.  Since I expect you would recognize the issue if you had seen it, I consider it possible that linux IDLE is immune.

After running a file, I would like f5 to re-run the same file.  Trying to run the contents of Shell, starting with the start-up message, is laughably useless.
msg331738 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-12-13 03:41
FWIW, I have this problem every day.  Am running on macOS.  This behavior has been seen for years and still persists on the latest IDLE that ships with a stock 3.7.1 from
msg331741 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-12-13 05:37
Raymond: I agree that daily would be obnoxious.  For me it is more like once a month or maybe less.  Can you give any detail about the factors I mentioned?  I currently have no idea where to start looking.
msg410740 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-01-17 04:10
I finally caught an example, which was not immediately after restart.  I copied the two lines of output, entered 'import re\n' and the copied text was pasted, then the line with the addition compiled, leading to the error.

Type "help", "copyright", "credits" or "license()" for more information.
>>> for c in '℘·': hex(ord(c))
>>> import re'0x2118'
... '0xb7'
SyntaxError: invalid syntax
>>> for c in '℘·': hex(ord(c))

I pasted the copied output into an issue on the browser and did other stuff before coming back to this window to try something with re.

Differences from my initial report: No RESTART (though usually or often is), no exception, not first entry (but first time not?).  

Edit menu item 'Paste' and the shortcut are bound to IDLE-defined pseudoevent '<<paste>>' which invokes method EditorWindow.paste which calls event_generate('<<Paste>>'), where the latter event is a tk-defined event. Where triggered?  I could add a print-to-console in .paste?  Happening only in shell and after Enter suggest looking as shell-specific part of Enter handling.  If never on Linux, could x-11-only fix-x11-paste (called in pyshell.main) explain why not?

I searched stackoverflow [tkinter] questions for 'paste'.  Got 840 responses, looked as first page, saw nothing relevant.  Adding 'unwanted', 'unexpected', or 'spontaneous' resulted in no hits.  I will consider asking a question myself.
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79648
2022-01-17 04:10:46terry.reedysetnosy: + epaine
messages: + msg410740
2019-03-20 16:37:01terry.reedysetassignee: terry.reedy
components: + IDLE
2018-12-13 05:37:30terry.reedysetmessages: + msg331741
2018-12-13 03:41:01rhettingersetmessages: + msg331738
2018-12-13 03:30:12terry.reedysetmessages: + msg331737
2018-12-13 00:29:11cheryl.sabellasetmessages: + msg331723
2018-12-12 02:32:04terry.reedycreate