mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[3.11] gh-100814: Fix exception for invalid callable value of Tkinter image option (GH-107692) (GH-107723)
Passing a callable object as an option value to a Tkinter image now raises
the expected TclError instead of an AttributeError.
(cherry picked from commit 50e3cc9748
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
4cfbcffd3d
commit
af08bcab8f
3 changed files with 18 additions and 4 deletions
|
@ -4068,8 +4068,6 @@ class Image:
|
|||
elif kw: cnf = kw
|
||||
options = ()
|
||||
for k, v in cnf.items():
|
||||
if callable(v):
|
||||
v = self._register(v)
|
||||
options = options + ('-'+k, v)
|
||||
self.tk.call(('image', 'create', imgtype, name,) + options)
|
||||
self.name = name
|
||||
|
@ -4096,8 +4094,6 @@ class Image:
|
|||
for k, v in _cnfmerge(kw).items():
|
||||
if v is not None:
|
||||
if k[-1] == '_': k = k[:-1]
|
||||
if callable(v):
|
||||
v = self._register(v)
|
||||
res = res + ('-'+k, v)
|
||||
self.tk.call((self.name, 'config') + res)
|
||||
|
||||
|
|
|
@ -144,6 +144,14 @@ class BitmapImageTest(AbstractTkTest, unittest.TestCase):
|
|||
self.assertEqual(image['foreground'],
|
||||
'-foreground {} {} #000000 yellow')
|
||||
|
||||
def test_bug_100814(self):
|
||||
# gh-100814: Passing a callable option value causes AttributeError.
|
||||
with self.assertRaises(tkinter.TclError):
|
||||
tkinter.BitmapImage('::img::test', master=self.root, spam=print)
|
||||
image = tkinter.BitmapImage('::img::test', master=self.root)
|
||||
with self.assertRaises(tkinter.TclError):
|
||||
image.configure(spam=print)
|
||||
|
||||
|
||||
class PhotoImageTest(AbstractTkTest, unittest.TestCase):
|
||||
|
||||
|
@ -274,6 +282,14 @@ class PhotoImageTest(AbstractTkTest, unittest.TestCase):
|
|||
image.configure(palette='3/4/2')
|
||||
self.assertEqual(image['palette'], '3/4/2')
|
||||
|
||||
def test_bug_100814(self):
|
||||
# gh-100814: Passing a callable option value causes AttributeError.
|
||||
with self.assertRaises(tkinter.TclError):
|
||||
tkinter.PhotoImage('::img::test', master=self.root, spam=print)
|
||||
image = tkinter.PhotoImage('::img::test', master=self.root)
|
||||
with self.assertRaises(tkinter.TclError):
|
||||
image.configure(spam=print)
|
||||
|
||||
def test_blank(self):
|
||||
image = self.create()
|
||||
image.blank()
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Passing a callable object as an option value to a Tkinter image now raises
|
||||
the expected TclError instead of an AttributeError.
|
Loading…
Add table
Add a link
Reference in a new issue