diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-16 16:00:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-16 16:00:47 (GMT) |
commit | 21fbf1631d37fd5f769fde5795c62e1f1e90842a (patch) | |
tree | d898e8c9b8b88b11d2faec78d7692f989991e665 /Lib/idlelib/macosx.py | |
parent | b5874fae0a618e4b0815a54242b0703bd92482be (diff) | |
download | cpython-21fbf1631d37fd5f769fde5795c62e1f1e90842a.zip cpython-21fbf1631d37fd5f769fde5795c62e1f1e90842a.tar.gz cpython-21fbf1631d37fd5f769fde5795c62e1f1e90842a.tar.bz2 |
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 35fa5d5e7f2b0971b39b2659dc70cb77e34a7dd6)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/macosx.py')
-rw-r--r-- | Lib/idlelib/macosx.py | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/Lib/idlelib/macosx.py b/Lib/idlelib/macosx.py index 12399f1..89b6457 100644 --- a/Lib/idlelib/macosx.py +++ b/Lib/idlelib/macosx.py @@ -4,7 +4,6 @@ A number of functions that enhance IDLE on macOS. from os.path import expanduser import plistlib from sys import platform # Used in _init_tk_type, changed by test. -from test.support import requires, ResourceDenied import tkinter @@ -16,27 +15,38 @@ _tk_type = None def _init_tk_type(): """ Initialize _tk_type for isXyzTk functions. + + This function is only called once, when _tk_type is still None. """ global _tk_type if platform == 'darwin': - try: - requires('gui') - except ResourceDenied: # Possible when testing. - _tk_type = "cocoa" # Newest and most common. - else: - root = tkinter.Tk() - ws = root.tk.call('tk', 'windowingsystem') - if 'x11' in ws: - _tk_type = "xquartz" - elif 'aqua' not in ws: - _tk_type = "other" - elif 'AppKit' in root.tk.call('winfo', 'server', '.'): + + # When running IDLE, GUI is present, test/* may not be. + # When running tests, test/* is present, GUI may not be. + # If not, guess most common. Does not matter for testing. + from idlelib.__init__ import testing + if testing: + from test.support import requires, ResourceDenied + try: + requires('gui') + except ResourceDenied: _tk_type = "cocoa" - else: - _tk_type = "carbon" - root.destroy() + return + + root = tkinter.Tk() + ws = root.tk.call('tk', 'windowingsystem') + if 'x11' in ws: + _tk_type = "xquartz" + elif 'aqua' not in ws: + _tk_type = "other" + elif 'AppKit' in root.tk.call('winfo', 'server', '.'): + _tk_type = "cocoa" + else: + _tk_type = "carbon" + root.destroy() else: _tk_type = "other" + return def isAquaTk(): """ |