]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44404: tkinter `after` support callable classes (GH-26812)
authorE-Paine <63801254+E-Paine@users.noreply.github.com>
Wed, 23 Jun 2021 10:30:24 +0000 (11:30 +0100)
committerGitHub <noreply@github.com>
Wed, 23 Jun 2021 10:30:24 +0000 (13:30 +0300)
Lib/tkinter/__init__.py
Lib/tkinter/test/test_tkinter/test_misc.py
Misc/NEWS.d/next/Library/2021-06-20-19-01-11.bpo-44404.McfrYB.rst [new file with mode: 0644]

index 369004c9d1b3d4c4d42b10865593198a18d77a32..2513c972bc77f0701f45bd9514575768368e764b 100644 (file)
@@ -841,7 +841,11 @@ class Misc:
                         self.deletecommand(name)
                     except TclError:
                         pass
-            callit.__name__ = func.__name__
+            try:
+                callit.__name__ = func.__name__
+            except AttributeError:
+                # Required for callable classes (bpo-44404)
+                callit.__name__ = type(func).__name__
             name = self._register(callit)
             return self.tk.call('after', ms, name)
 
index d4b7cbd867bc046f852a2c3835f86cb542919269..ab8f64790dfc0e17f0549ee3c3ed23ac97e67983 100644 (file)
@@ -1,3 +1,4 @@
+import functools
 import unittest
 import tkinter
 import enum
@@ -98,6 +99,12 @@ class MiscTest(AbstractTkTest, unittest.TestCase):
         with self.assertRaises(tkinter.TclError):
             root.tk.call(script)
 
+        # Call with a callable class
+        count = 0
+        timer1 = root.after(0, functools.partial(callback, 42, 11))
+        root.update()  # Process all pending events.
+        self.assertEqual(count, 53)
+
     def test_after_idle(self):
         root = self.root
 
diff --git a/Misc/NEWS.d/next/Library/2021-06-20-19-01-11.bpo-44404.McfrYB.rst b/Misc/NEWS.d/next/Library/2021-06-20-19-01-11.bpo-44404.McfrYB.rst
new file mode 100644 (file)
index 0000000..ff6ca1b
--- /dev/null
@@ -0,0 +1 @@
+:mod:`tkinter`'s ``after()`` method now supports callables without the ``__name__`` attribute.