summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/run.py
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2019-05-25 01:59:53 (GMT)
committerGitHub <noreply@github.com>2019-05-25 01:59:53 (GMT)
commit81bb97df6138c755e229dcdac9bed747e31b61b3 (patch)
tree7822fe2810e11b0ce479251934361b878acaf25c /Lib/idlelib/run.py
parent1bbf7b661f0ac8aac12d5531928d9a85c98ec1a9 (diff)
downloadcpython-81bb97df6138c755e229dcdac9bed747e31b61b3.zip
cpython-81bb97df6138c755e229dcdac9bed747e31b61b3.tar.gz
cpython-81bb97df6138c755e229dcdac9bed747e31b61b3.tar.bz2
bpo-37038: Make idlelib.run runnable; add test clause (GH-13560)
Diffstat (limited to 'Lib/idlelib/run.py')
-rw-r--r--Lib/idlelib/run.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index b4a2b54..4075dee 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -1,3 +1,9 @@
+""" idlelib.run
+
+Simplified, pyshell.ModifiedInterpreter spawns a subprocess with
+f'''{sys.executable} -c "__import__('idlelib.run').run.main()"'''
+'.run' is needed because __import__ returns idlelib, not idlelib.run.
+"""
import io
import linecache
import queue
@@ -8,8 +14,6 @@ import _thread as thread
import threading
import warnings
-import tkinter # Tcl, deletions, messagebox if startup fails
-
from idlelib import autocomplete # AutoComplete, fetch_encodings
from idlelib import calltip # Calltip
from idlelib import debugger_r # start_debugger
@@ -19,11 +23,16 @@ from idlelib import rpc # multiple objects
from idlelib import stackviewer # StackTreeItem
import __main__
-for mod in ('simpledialog', 'messagebox', 'font',
- 'dialog', 'filedialog', 'commondialog',
- 'ttk'):
- delattr(tkinter, mod)
- del sys.modules['tkinter.' + mod]
+import tkinter # Use tcl and, if startup fails, messagebox.
+if not hasattr(sys.modules['idlelib.run'], 'firstrun'):
+ # Undo modifications of tkinter by idlelib imports; see bpo-25507.
+ for mod in ('simpledialog', 'messagebox', 'font',
+ 'dialog', 'filedialog', 'commondialog',
+ 'ttk'):
+ delattr(tkinter, mod)
+ del sys.modules['tkinter.' + mod]
+ # Avoid AttributeError if run again; see bpo-37038.
+ sys.modules['idlelib.run'].firstrun = False
LOCALHOST = '127.0.0.1'
@@ -523,4 +532,9 @@ class Executive(object):
item = stackviewer.StackTreeItem(flist, tb)
return debugobj_r.remote_object_tree_item(item)
-capture_warnings(False) # Make sure turned off; see issue 18081
+
+if __name__ == '__main__':
+ from unittest import main
+ main('idlelib.idle_test.test_run', verbosity=2)
+
+capture_warnings(False) # Make sure turned off; see bpo-18081.