]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-100814: Fix exception for invalid callable value of Tkinter image option...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 16 Aug 2023 08:07:02 +0000 (01:07 -0700)
committerGitHub <noreply@github.com>
Wed, 16 Aug 2023 08:07:02 +0000 (11:07 +0300)
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 50e3cc9748eb2103eb7ed6cc5a74d177df3cfb13)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/tkinter/__init__.py
Lib/tkinter/test/test_tkinter/test_images.py
Misc/NEWS.d/next/Library/2023-08-06-15-29-00.gh-issue-100814.h195gW.rst [new file with mode: 0644]

index 054034098880f0f079c8f4030462feb0d7d04e74..6ae9839055382cdd06e758db4d0a603ad61c618d 100644 (file)
@@ -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)
 
index 8b473cce5f9947e559b375a5dbe41e035d13a313..5b3566a3611eb5dfdbe533bb60f9f6bc05fea3bc 100644 (file)
@@ -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()
diff --git a/Misc/NEWS.d/next/Library/2023-08-06-15-29-00.gh-issue-100814.h195gW.rst b/Misc/NEWS.d/next/Library/2023-08-06-15-29-00.gh-issue-100814.h195gW.rst
new file mode 100644 (file)
index 0000000..86cb7bf
--- /dev/null
@@ -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.