Skip to content

Commit e50d233

Browse files
authored
gh-156896: Stop scrubbing tkinker submodules upon idlelib.run import (#156915)
Instead, invoke the scrubbing within run.main, which is called after the import when starting the IDLE user process. To manually test that scrub_tkinter_submodules is called when proper, start (or restart) Shell, enter `import tkinter; dir(tkinter), and check that that font, messagebox, ttk, and the dialog modules are missing. It is obvious from the code that the function is not otherwise called. To test anyway, continue with `import tkinter.ttk; import idlelib.run; tkinter.ttk` and check for proper output.
1 parent 112560e commit e50d233

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

Lib/idlelib/run.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
""" idlelib.run
22
3-
Simplified, pyshell.ModifiedInterpreter spawns a subprocess with
3+
Simplified: pyshell.ModifiedInterpreter spawns a subprocess with
44
f'''{sys.executable} -c "__import__('idlelib.run').run.main()"'''
55
'.run' is needed because __import__ returns idlelib, not idlelib.run.
66
"""
@@ -26,11 +26,12 @@
2626
from idlelib import rpc # multiple objects
2727
from idlelib import stackviewer # StackTreeItem
2828
from idlelib import util # fix_scaling
29-
import __main__
29+
import __main__ # self.locals in Executive.__init__.
3030

3131
import tkinter # Use tcl and, if startup fails, messagebox.
32-
if not hasattr(sys.modules['idlelib.run'], 'firstrun'):
33-
# Undo modifications of tkinter by idlelib imports; see bpo-25507.
32+
33+
def scrub_tkinter_submodules(): # Call in main when starting user process.
34+
# Undo modifications of tkinter by idlelib imports; see gh-69693.
3435
# Which of these submodules got imported (and thus added as a tkinter
3536
# attribute) depends on what idlelib pulled in, so tolerate missing
3637
# ones rather than assuming a fixed set; see gh-59396.
@@ -42,8 +43,6 @@
4243
del sys.modules['tkinter.' + mod]
4344
except (AttributeError, KeyError):
4445
pass
45-
# Avoid AttributeError if run again; see bpo-37038.
46-
sys.modules['idlelib.run'].firstrun = False
4746

4847
LOCALHOST = '127.0.0.1'
4948

@@ -139,6 +138,9 @@ def main(del_exitfunc=False):
139138
register and unregister themselves.
140139
141140
"""
141+
142+
scrub_tkinter_submodules()
143+
142144
global exit_now
143145
global quitting
144146
global no_exitfunc
@@ -705,8 +707,7 @@ def stackviewer(self, flist_oid=None):
705707
item = stackviewer.StackTreeItem(exc, flist)
706708
return debugobj_r.remote_object_tree_item(item)
707709

708-
709-
if __name__ == '__main__':
710+
if __name__ == '__main__': # __name__ is 'idlelib.run' in user subprocess.
710711
from unittest import main
711712
main('idlelib.idle_test.test_run', verbosity=2)
712713

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stop deleting tkinter submodules when idlelib.run is imported.

0 commit comments

Comments
 (0)