Skip to content

Commit c70ab1c

Browse files
bpo-37038: Make idlelib.run runnable; add test clause (GH-13560)
(cherry picked from commit 81bb97d) Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent cee4ac8 commit c70ab1c

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

Lib/idlelib/NEWS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Released on 2019-06-24?
33
======================================
44

55

6+
bpo-37038: Make idlelib.run runnable; add test clause.
7+
68
bpo-36958: Print any argument other than None or int passed to
79
SystemExit or sys.exit().
810

Lib/idlelib/run.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
""" idlelib.run
2+
3+
Simplified, pyshell.ModifiedInterpreter spawns a subprocess with
4+
f'''{sys.executable} -c "__import__('idlelib.run').run.main()"'''
5+
'.run' is needed because __import__ returns idlelib, not idlelib.run.
6+
"""
17
import io
28
import linecache
39
import queue
@@ -8,8 +14,6 @@
814
import threading
915
import warnings
1016

11-
import tkinter # Tcl, deletions, messagebox if startup fails
12-
1317
from idlelib import autocomplete # AutoComplete, fetch_encodings
1418
from idlelib import calltip # Calltip
1519
from idlelib import debugger_r # start_debugger
@@ -19,11 +23,16 @@
1923
from idlelib import stackviewer # StackTreeItem
2024
import __main__
2125

22-
for mod in ('simpledialog', 'messagebox', 'font',
23-
'dialog', 'filedialog', 'commondialog',
24-
'ttk'):
25-
delattr(tkinter, mod)
26-
del sys.modules['tkinter.' + mod]
26+
import tkinter # Use tcl and, if startup fails, messagebox.
27+
if not hasattr(sys.modules['idlelib.run'], 'firstrun'):
28+
# Undo modifications of tkinter by idlelib imports; see bpo-25507.
29+
for mod in ('simpledialog', 'messagebox', 'font',
30+
'dialog', 'filedialog', 'commondialog',
31+
'ttk'):
32+
delattr(tkinter, mod)
33+
del sys.modules['tkinter.' + mod]
34+
# Avoid AttributeError if run again; see bpo-37038.
35+
sys.modules['idlelib.run'].firstrun = False
2736

2837
LOCALHOST = '127.0.0.1'
2938

@@ -523,4 +532,9 @@ def stackviewer(self, flist_oid=None):
523532
item = stackviewer.StackTreeItem(flist, tb)
524533
return debugobj_r.remote_object_tree_item(item)
525534

526-
capture_warnings(False) # Make sure turned off; see issue 18081
535+
536+
if __name__ == '__main__':
537+
from unittest import main
538+
main('idlelib.idle_test.test_run', verbosity=2)
539+
540+
capture_warnings(False) # Make sure turned off; see bpo-18081.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make idlelib.run runnable; add test clause.

0 commit comments

Comments
 (0)