Skip to content

Commit

Permalink
bpo-44404: tkinter after support callable classes (GH-26812)
Browse files Browse the repository at this point in the history
  • Loading branch information
E-Paine committed Jun 23, 2021
1 parent 5c79402 commit e9c8f78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,11 @@ def callit():
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)

Expand Down
7 changes: 7 additions & 0 deletions Lib/tkinter/test/test_tkinter/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import unittest
import tkinter
import enum
Expand Down Expand Up @@ -98,6 +99,12 @@ def callback(start=0, step=1):
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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`tkinter`'s ``after()`` method now supports callables without the ``__name__`` attribute.

0 comments on commit e9c8f78

Please sign in to comment.