mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
gh-97527: IDLE: protect macosx Tk() call when no GUI (GH-97530)
Only call tkinter.tk and its follow-up code in _init_tk_type when requires('gui')
does not raise. This function can be called as an unintended side-effect of
calling other idlelib code as part of tests on macOS without a GUI enabled.
(cherry picked from commit 9704f8da33
)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
2a50772b63
commit
a7a7da4acf
1 changed files with 17 additions and 13 deletions
|
@ -4,6 +4,7 @@ A number of functions that enhance IDLE on macOS.
|
||||||
from os.path import expanduser
|
from os.path import expanduser
|
||||||
import plistlib
|
import plistlib
|
||||||
from sys import platform # Used in _init_tk_type, changed by test.
|
from sys import platform # Used in _init_tk_type, changed by test.
|
||||||
|
from test.support import requires, ResourceDenied
|
||||||
|
|
||||||
import tkinter
|
import tkinter
|
||||||
|
|
||||||
|
@ -14,12 +15,15 @@ import tkinter
|
||||||
_tk_type = None
|
_tk_type = None
|
||||||
|
|
||||||
def _init_tk_type():
|
def _init_tk_type():
|
||||||
"""
|
""" Initialize _tk_type for isXyzTk functions.
|
||||||
Initializes OS X Tk variant values for
|
|
||||||
isAquaTk(), isCarbonTk(), isCocoaTk(), and isXQuartz().
|
|
||||||
"""
|
"""
|
||||||
global _tk_type
|
global _tk_type
|
||||||
if platform == 'darwin':
|
if platform == 'darwin':
|
||||||
|
try:
|
||||||
|
requires('gui')
|
||||||
|
except ResourceDenied: # Possible when testing.
|
||||||
|
_tk_type = "cocoa" # Newest and most common.
|
||||||
|
else:
|
||||||
root = tkinter.Tk()
|
root = tkinter.Tk()
|
||||||
ws = root.tk.call('tk', 'windowingsystem')
|
ws = root.tk.call('tk', 'windowingsystem')
|
||||||
if 'x11' in ws:
|
if 'x11' in ws:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue