8000 gh-100814: Fix exception for invalid callable value of Tkinter image … · python/cpython@fc8f2ae · GitHub
[go: up one dir, main page]

Skip to content

Commit fc8f2ae

Browse files
serhiy-storchakapull[bot]
authored andcommitted
gh-100814: Fix exception for invalid callable value of Tkinter image option (GH-107692)
Passing a callable object as an option value to a Tkinter image now raises the expected TclError instead of an AttributeError.
1 parent 99f5be3 commit fc8f2ae

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Lib/test/test_tkinter/test_images.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ def test_configure_foreground(self):
144144
self.assertEqual(image['foreground'],
145145
'-foreground {} {} #000000 yellow')
146146

147+
def test_bug_100814(self):
148+
# gh-100814: Passing a callable option value causes AttributeError.
149+
with self.assertRaises(tkinter.TclError):
150+
tkinter.BitmapImage('::img::test', master=self.root, spam=print)
151+
image = tkinter.BitmapImage('::img::test', master=self.root)
152+
with self.assertRaises(tkinter.TclError):
153+
image.configure(spam=print)
154+
147155

148156
class PhotoImageTest(AbstractTkTest, unittest.TestCase):
149157

@@ -274,6 +282,14 @@ def test_configure_palette(self):
274282
image.configure(palette='3/4/2')
275283
self.assertEqual(image['palette'], '3/4/2')
276284

285+
def test_bug_100814(self):
286+
# gh-100814: Passing a callable option value causes AttributeError.
287+
with self.assertRaises(tkinter.TclError):
288+
tkinter.PhotoImage('::img::test', master=self.root, spam=print)
289+
image = tkinter.PhotoImage('::img::test', master=self.root)
290+
with self.assertRaises(tkinter.TclError):
291+
image.configure(spam=print)
292+
277293
def test_blank(self):
278294
8000 image = self.create()
279295
image.blank()

Lib/tkinter/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4069,8 +4069,6 @@ def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
40694069
elif kw: cnf = kw
40704070
options = ()
40714071
for k, v in cnf.items():
4072-
if callable(v):
4073-
v = self._register(v)
40744072
options = options + ('-'+k, v)
40754073
self.tk.call(('image', 'create', imgtype, name,) + options)
40764074
self.name = name
@@ -4097,8 +4095,6 @@ def configure(self, **kw):
40974095
for k, v in _cnfmerge(kw).items():
40984096
if v is not None:
40994097
if k[-1] == '_': k = k[:-1]
4100-
if callable(v):
4101-
v = self._register(v)
41024098
res = res + ('-'+k, v)
41034099
self.tk.call((self.name, 'config') + res)
41044100

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Passing a callable object as an option value to a Tkinter image now raises
2+
the expected TclError instead of an AttributeError.

0 commit comments

Comments
 (0)
0