Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDLE: unrequested pasting into Shell after restart #79648

Open
terryjreedy opened this issue Dec 12, 2018 · 8 comments
Open

IDLE: unrequested pasting into Shell after restart #79648

terryjreedy opened this issue Dec 12, 2018 · 8 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

BPO 35467
Nosy @rhettinger, @terryjreedy, @taleinat, @csabella, @E-Paine

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/terryjreedy'
closed_at = None
created_at = <Date 2018-12-12.02:32:04.008>
labels = ['3.8', 'expert-IDLE', 'type-bug', '3.7']
title = 'IDLE: unrequested pasting into Shell after restart'
updated_at = <Date 2022-01-17.04:10:46.657>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2022-01-17.04:10:46.657>
actor = 'terry.reedy'
assignee = 'terry.reedy'
closed = False
closed_date = None
closer = None
components = ['IDLE']
creation = <Date 2018-12-12.02:32:04.008>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 35467
keywords = []
message_count = 6.0
messages = ['331668', '331723', '331737', '331738', '331741', '410740']
nosy_count = 5.0
nosy_names = ['rhettinger', 'terry.reedy', 'taleinat', 'cheryl.sabella', 'epaine']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue35467'
versions = ['Python 3.7', 'Python 3.8']

@terryjreedy
Copy link
Member Author

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.

tem3.py: (content likely not relevant)

import inspect
class A:
    pass
print(inspect.getsource(A))
print(__name__)
Shell copy:
"""
...
OSError: could not find class definition
>>> 
======================== RESTART: F:\Python\a\tem3.py 

========================

class A:
    pass
__main__
>>> 1/0======================== RESTART: F:\Python\a\tem3.py 

========================

class A:
    pass
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.

@terryjreedy terryjreedy added 3.7 (EOL) end of life 3.8 only security fixes type-bug An unexpected behavior, bug, or error labels Dec 12, 2018
@csabella
Copy link
Contributor

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.

@terryjreedy
Copy link
Member Author

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.

@rhettinger
Copy link
Contributor

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 python.org.

@terryjreedy
Copy link
Member Author

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.

@terryjreedy terryjreedy self-assigned this Mar 20, 2019
@terryjreedy
Copy link
Member Author

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))
... 
'0x2118'
'0xb7'
>>> 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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@terryjreedy
Copy link
Member Author

Fairly consistent reproducer (at least 10 times): open Shell and editor (no code needed); copy from Shell; switch to editor; hts F5; after >>> and maybe entry, hit return. Copied text is pasted. Does not happen if much of any extra action after paste.

Or F5 to restart, select, ^C to copy, return (without clicking to move cursor back to prompt), and copied text is pasted after prompt. (The prompt is now in sidebar, but issue predates it by years.) Hit return and get error. Can repeat copy, return, and unexpected-paste followed by error as long as only click to select and only hit return after copy.

I tried experiment above of adding print(event) to paste handler and it is not invoked for ghost pasting. Next experiment will be to find where in newline handler it happens.

@terryjreedy
Copy link
Member Author

>>> import multiprocessing
>>> multiprocessing.Queue
<bound method BaseContext.Queue of <multiprocessing.context.DefaultContext object at 0x000002610976A660>>
>>> def f(a, *b, *, c=0): passimport multiprocessing
... multiprocessing.Queue
... <bound method BaseContext.Queue of <multiprocessing.context.DefaultContext object at 0x000002610976A660>>

I did a copy with prompts of the first 3 lines before entering the 4th and getting the unwanted copy pasted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes topic-IDLE type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

3 participants