Skip to content

Commit 21fbf16

Browse files
gh-97527: IDLE - fix buggy macosx patch (GH-98313)
GH-97530 fixed IDLE tests possibly crashing on a Mac without a GUI. But it resulted in IDLE not starting in 3.10.8, 3.12.0a1, and Microsoft Python 3.10.2288.0 when test/* is not installed. After this patch, test.* is only imported when testing on Mac. (cherry picked from commit 35fa5d5) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent b5874fa commit 21fbf16

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

Lib/idlelib/NEWS.txt

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Released on 2022-10-03
44
=========================
55

66

7+
gh-97527: Fix a bug in the previous bugfix that caused IDLE to not
8+
start when run with 3.10.8, 3.12.0a1, and at least Microsoft Python
9+
3.10.2288.0 installed without the Lib/test package. 3.11.0 was never
10+
affected.
11+
712
gh-65802: Document handling of extensions in Save As dialogs.
813

914
gh-95191: Include prompts when saving Shell (interactive input/output).

Lib/idlelib/macosx.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from os.path import expanduser
55
import plistlib
66
from sys import platform # Used in _init_tk_type, changed by test.
7-
from test.support import requires, ResourceDenied
87

98
import tkinter
109

@@ -16,27 +15,38 @@
1615

1716
def _init_tk_type():
1817
""" Initialize _tk_type for isXyzTk functions.
18+
19+
This function is only called once, when _tk_type is still None.
1920
"""
2021
global _tk_type
2122
if platform == 'darwin':
22-
try:
23-
requires('gui')
24-
except ResourceDenied: # Possible when testing.
25-
_tk_type = "cocoa" # Newest and most common.
26-
else:
27-
root = tkinter.Tk()
28-
ws = root.tk.call('tk', 'windowingsystem')
29-
if 'x11' in ws:
30-
_tk_type = "xquartz"
31-
elif 'aqua' not in ws:
32-
_tk_type = "other"
33-
elif 'AppKit' in root.tk.call('winfo', 'server', '.'):
23+
24+
# When running IDLE, GUI is present, test/* may not be.
25+
# When running tests, test/* is present, GUI may not be.
26+
# If not, guess most common. Does not matter for testing.
27+
from idlelib.__init__ import testing
28+
if testing:
29+
from test.support import requires, ResourceDenied
30+
try:
31+
requires('gui')
32+
except ResourceDenied:
3433
_tk_type = "cocoa"
35-
else:
36-
_tk_type = "carbon"
37-
root.destroy()
34+
return
35+
36+
root = tkinter.Tk()
37+
ws = root.tk.call('tk', 'windowingsystem')
38+
if 'x11' in ws:
39+
_tk_type = "xquartz"
40+
elif 'aqua' not in ws:
41+
_tk_type = "other"
42+
elif 'AppKit' in root.tk.call('winfo', 'server', '.'):
43+
_tk_type = "cocoa"
44+
else:
45+
_tk_type = "carbon"
46+
root.destroy()
3847
else:
3948
_tk_type = "other"
49+
return
4050

4151
def isAquaTk():
4252
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a bug in the previous bugfix that caused IDLE to not start when run with
2+
3.10.8, 3.12.0a1, and at least Microsoft Python 3.10.2288.0 installed
3+
without the Lib/test package. 3.11.0 was never affected.

0 commit comments

Comments
 (0)