Skip to content

[3.8] bpo-23544: Disable IDLE Stack Viewer when running user code (GH-17163) #24366

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

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/idlelib/NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Released on 2021-02-15?
======================================


bpo-23544: Disable Debug=>Stack Viewer when user code is running or
Debugger is active, to prevent hang or crash. Patch by Zackery Spytz.

bpo-43008: Make IDLE invoke :func:`sys.excepthook` in normal,
2-process mode.

Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/codecontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def toggle_code_context_event(self, event=None):
self.text.after_cancel(self.t1)
self._reset()
menu_status = 'Show'
self.editwin.update_menu_label(menu='options', index='* Code Context',
self.editwin.update_menu_label(menu='options', index='*ode*ontext',
label=f'{menu_status} Code Context')
return "break"

Expand Down
10 changes: 6 additions & 4 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
text.bind("<<toggle-code-context>>",
self.code_context.toggle_code_context_event)
else:
self.update_menu_state('options', '*Code Context', 'disabled')
self.update_menu_state('options', '*ode*ontext', 'disabled')
if self.allow_line_numbers:
self.line_numbers = self.LineNumbers(self)
if idleConf.GetOption('main', 'EditorWindow',
'line-numbers-default', type='bool'):
self.toggle_line_numbers_event()
text.bind("<<toggle-line-numbers>>", self.toggle_line_numbers_event)
else:
self.update_menu_state('options', '*Line Numbers', 'disabled')
self.update_menu_state('options', '*ine*umbers', 'disabled')

def handle_winconfig(self, event=None):
self.set_width()
Expand Down Expand Up @@ -450,7 +450,9 @@ def createmenubar(self):
self.menudict = menudict = {}
for name, label in self.menu_specs:
underline, label = prepstr(label)
menudict[name] = menu = Menu(mbar, name=name, tearoff=0)
postcommand = getattr(self, f'{name}_menu_postcommand', None)
menudict[name] = menu = Menu(mbar, name=name, tearoff=0,
postcommand=postcommand)
mbar.add_cascade(label=label, menu=menu, underline=underline)
if macosx.isCarbonTk():
# Insert the application menu
Expand Down Expand Up @@ -1527,7 +1529,7 @@ def toggle_line_numbers_event(self, event=None):
else:
self.line_numbers.show_sidebar()
menu_label = "Hide"
self.update_menu_label(menu='options', index='*Line Numbers',
self.update_menu_label(menu='options', index='*ine*umbers',
label=f'{menu_label} Line Numbers')

# "line.col" -> line, as an int
Expand Down
21 changes: 21 additions & 0 deletions Lib/idlelib/idle_test/test_mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Reported as 88%; mocking turtledemo absence would have no point.

from idlelib import mainmenu
import re
import unittest


Expand All @@ -16,6 +17,26 @@ def test_menudefs(self):
def test_default_keydefs(self):
self.assertGreaterEqual(len(mainmenu.default_keydefs), 50)

def test_tcl_indexes(self):
# Test tcl patterns used to find menuitem to alter.
# On failure, change pattern here and in function(s).
# Patterns here have '.*' for re instead of '*' for tcl.
for menu, pattern in (
('debug', '.*tack.*iewer'), # PyShell.debug_menu_postcommand
('options', '.*ode.*ontext'), # EW.__init__, CodeContext.toggle...
('options', '.*ine.*umbers'), # EW.__init__, EW.toggle...event.
):
with self.subTest(menu=menu, pattern=pattern):
for menutup in mainmenu.menudefs:
if menutup[0] == menu:
break
else:
self.assertTrue(0, f"{menu} not in menudefs")
self.assertTrue(any(re.search(pattern, menuitem[0])
for menuitem in menutup[1]
if menuitem is not None), # Separator.
f"{pattern} not in {menu}")


if __name__ == '__main__':
unittest.main(verbosity=2)
4 changes: 4 additions & 0 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,10 @@ def open_debugger(self):
self.showprompt()
self.set_debugger_indicator()

def debug_menu_postcommand(self):
state = 'disabled' if self.executing else 'normal'
self.update_menu_state('debug', '*tack*iewer', state)

def beginexecuting(self):
"Helper for ModifiedInterpreter"
self.resetoutput()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Disable Debug=>Stack Viewer when user code is running or Debugger
is active, to prevent hang or crash. Patch by Zackery Spytz.