New submission from Terry J. Reedy <[email protected]>:
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
try:
s = str(sys.ps1)
except:
s = ""
self.console.write(s)
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 #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 #13039 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.
----------
assignee: terry.reedy
components: IDLE
messages: 304860
nosy: terry.reedy
priority: normal
severity: normal
stage: test needed
status: open
title: IDLE: cleanup use of sys.ps1 and never set it.
type: behavior
versions: Python 3.6, Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue31858>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com