Skip to content

Commit 7a97e4b

Browse files
gh-59396: Tolerate absent tkinter dialog submodules in idlelib.run
filedialog no longer imports tkinter.dialog, so that submodule is not always present when run.py undoes idlelib's tkinter imports; skip the ones that are missing instead of raising. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9fce9ed commit 7a97e4b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Lib/idlelib/run.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@
3030
import tkinter # Use tcl and, if startup fails, messagebox.
3131
if not hasattr(sys.modules['idlelib.run'], 'firstrun'):
3232
# Undo modifications of tkinter by idlelib imports; see bpo-25507.
33+
# Which of these submodules got imported (and thus added as a tkinter
34+
# attribute) depends on what idlelib pulled in, so tolerate missing
35+
# ones rather than assuming a fixed set; see gh-59396.
3336
for mod in ('simpledialog', 'messagebox', 'font',
3437
'dialog', 'filedialog', 'commondialog',
3538
'ttk'):
36-
delattr(tkinter, mod)
37-
del sys.modules['tkinter.' + mod]
39+
try:
40+
delattr(tkinter, mod)
41+
del sys.modules['tkinter.' + mod]
42+
except (AttributeError, KeyError):
43+
pass
3844
# Avoid AttributeError if run again; see bpo-37038.
3945
sys.modules['idlelib.run'].firstrun = False
4046

0 commit comments

Comments
 (0)