-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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: cleanup use of sys.ps1 and never set it. #76039
Comments
This issue is about cleaning up IDLE's use of sys.ps1 for its prompt (sys.ps2 is not used). A. This will make for cleaner code and fix some bugs. B. This will be better for testing. (Some possible changes to pyshell might make sys.ps1 irrelevant, but that is for the future.) Part1. editor.EditorWindow.__init__ sets sys.ps1 to '>>> ' if not set.
try:
sys.ps1
except AttributeError:
sys.ps1 = '>>> '
IDLE initially respects a user setting of sys.ps1 in a startup file.
pyshell.PyShell.open_debugger hasand .close_debugger has these lines
sys.ps1 = "[DEBUG ON]\n>>> "
sys.ps1 = ">>> "
These overwrite any user setting of sys.ps1. As long as IDLE pays attention to the initial value of sys.ps1, I consider this a bug. pyshell.PyShell.show_prompt starts with I suspect that this is a holdover from when IDLE executed user code in its own process, as it still does with the deprecated '-n' option. However, if a -n user deletes sys.ps1, the replacement should be '>>> ', not '' (bug 2). In the current default subprocess mode, users cannot change the IDLE process sys module (see bpo-13657), so rereading sys.ps1 for every editor window and prompt is nonsensical. Patch 1: replace the EditorWindow.__init__ code with module level code
sys_ps1 = sys.ps1 if hasattr(sys, 'ps1') else '>>> '
prompt = sys_ps1 Fix pyshell to import editor rather than two of its objects. In its debugger methods, set editor.prompt, using editor.sys_ps1, thus preserving any user setting. In print_prompt, print the current editor.prompt. (This will disable users resetting ps1 in deprecated -n mode, but I consider that okay as it matches the normal mode.) Part 2. The reason the prompt is set in EditorWindow, instead of where is it obviously needed, the PyShell subclass of the OutputWindow subclass of EditorWindow, is that it is currently used in EditorWindow.smart_backspace_event and .newline_and_indent_event, while pyshell imports editor (and must), and not the other way around. Treating the prompt text as special in an editor lead to a bug in smart_backspace that was fixed in python/cpython#57248 by guarding it use with self.context_use_ps1. There is still a nearly inconsequential bug in the newline method where the prompt use is not guarded. (Hitting newline with the cursor before the 't' in '>>> test' leaves the preceding space instead of deleting it.) Patch 2: Only the last line of the prompt is relevant in either method. I believe that replacing self.context_use_ps1 = False in an editor, = True in Shell with self.last_prompt_line = '' in an editor, = whatever it is in Shell, will allow moving sys_ps1 and prompt to pyshell. This would simplify patch 1. |
I put the new shell variables into PyShell itself. There is usually only one instance created in a session. I tested the patch manually in both shell and editor with both the default prompt and with sys.ps1 set before importing idlelib.idle. Beginning to automate tests for editor and shell is a project in itself. |
By mistake, I deleted the setting of context_use_ps1 in PyShell while still in use in several places. Fixed in bpo-34055. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: