Skip to content

Commit 51ec2f0

Browse files
authored
tkinter: Use a TypeVarTuple in .after() and .after_idle() methods (#11014)
1 parent a08d2d5 commit 51ec2f0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

stdlib/tkinter/__init__.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from tkinter.constants import *
66
from tkinter.font import _FontDescription
77
from types import TracebackType
88
from typing import Any, Generic, NamedTuple, TypeVar, overload, type_check_only
9-
from typing_extensions import Literal, TypeAlias, TypedDict, deprecated
9+
from typing_extensions import Literal, TypeAlias, TypedDict, TypeVarTuple, Unpack, deprecated
1010

1111
if sys.version_info >= (3, 9):
1212
__all__ = [
@@ -314,6 +314,8 @@ getdouble: Incomplete
314314

315315
def getboolean(s): ...
316316

317+
_Ts = TypeVarTuple("_Ts")
318+
317319
class _GridIndexInfo(TypedDict, total=False):
318320
minsize: _ScreenUnits
319321
pad: _ScreenUnits
@@ -349,9 +351,9 @@ class Misc:
349351
def tk_focusPrev(self) -> Misc | None: ...
350352
# .after() can be called without the "func" argument, but it is basically never what you want.
351353
# It behaves like time.sleep() and freezes the GUI app.
352-
def after(self, ms: int | Literal["idle"], func: Callable[..., object], *args: Any) -> str: ...
354+
def after(self, ms: int | Literal["idle"], func: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> str: ...
353355
# after_idle is essentially partialmethod(after, "idle")
354-
def after_idle(self, func: Callable[..., object], *args: Any) -> str: ...
356+
def after_idle(self, func: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> str: ...
355357
def after_cancel(self, id: str) -> None: ...
356358
def bell(self, displayof: Literal[0] | Misc | None = 0) -> None: ...
357359
def clipboard_get(self, *, displayof: Misc = ..., type: str = ...) -> str: ...

test_cases/stdlib/check_tkinter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ def custom_handler(exc: type[BaseException], val: BaseException, tb: types.Trace
1212
root = tkinter.Tk()
1313
root.report_callback_exception = traceback.print_exception
1414
root.report_callback_exception = custom_handler
15+
16+
17+
def foo(x: int, y: str) -> None:
18+
pass
19+
20+
21+
root.after(1000, foo, 10, "lol")
22+
root.after(1000, foo, 10, 10) # type: ignore

0 commit comments

Comments
 (0)