From e76f69fe9cff7c7b163b977a53a48abd1c76b255 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 10 Nov 2023 20:03:27 +0200 Subject: [PATCH 1/3] Use a TypeVarTuple in tkinter.after() and tkinter.after_idle() --- stdlib/tkinter/__init__.pyi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index d0eb97aa5ebd..1817665012e7 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -7,7 +7,7 @@ from tkinter.constants import * from tkinter.font import _FontDescription from types import TracebackType from typing import Any, Generic, NamedTuple, TypeVar, overload, type_check_only -from typing_extensions import Literal, TypeAlias, TypedDict, deprecated +from typing_extensions import Literal, TypeAlias, TypedDict, deprecated, Unpack, TypeVarTuple if sys.version_info >= (3, 9): __all__ = [ @@ -314,6 +314,8 @@ getdouble: Incomplete def getboolean(s): ... +_Ts = TypeVarTuple("_Ts") + class _GridIndexInfo(TypedDict, total=False): minsize: _ScreenUnits pad: _ScreenUnits @@ -349,9 +351,9 @@ class Misc: def tk_focusPrev(self) -> Misc | None: ... # .after() can be called without the "func" argument, but it is basically never what you want. # It behaves like time.sleep() and freezes the GUI app. - def after(self, ms: int | Literal["idle"], func: Callable[..., object], *args: Any) -> str: ... + def after(self, ms: int | Literal["idle"], func: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> str: ... # after_idle is essentially partialmethod(after, "idle") - def after_idle(self, func: Callable[..., object], *args: Any) -> str: ... + def after_idle(self, func: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> str: ... def after_cancel(self, id: str) -> None: ... def bell(self, displayof: Literal[0] | Misc | None = 0) -> None: ... def clipboard_get(self, *, displayof: Misc = ..., type: str = ...) -> str: ... From fc3c3760e65c1e6c5285c5d3a36854fc1ee392c1 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 10 Nov 2023 20:21:28 +0200 Subject: [PATCH 2/3] add test --- test_cases/stdlib/check_tkinter.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test_cases/stdlib/check_tkinter.py b/test_cases/stdlib/check_tkinter.py index cff352b061e3..9e6b64d64c7b 100644 --- a/test_cases/stdlib/check_tkinter.py +++ b/test_cases/stdlib/check_tkinter.py @@ -12,3 +12,10 @@ def custom_handler(exc: type[BaseException], val: BaseException, tb: types.Trace root = tkinter.Tk() root.report_callback_exception = traceback.print_exception root.report_callback_exception = custom_handler + + +def foo(x: int, y: str) -> None: + pass + +root.after(1000, foo, 10, "lol") +root.after(1000, foo, 10, 10) # type: ignore From 77db1709cfe0386a5d3966dcc8b7fd5392bd4cb7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Nov 2023 18:21:56 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tkinter/__init__.pyi | 2 +- test_cases/stdlib/check_tkinter.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 1817665012e7..5bffc1a21fe0 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -7,7 +7,7 @@ from tkinter.constants import * from tkinter.font import _FontDescription from types import TracebackType from typing import Any, Generic, NamedTuple, TypeVar, overload, type_check_only -from typing_extensions import Literal, TypeAlias, TypedDict, deprecated, Unpack, TypeVarTuple +from typing_extensions import Literal, TypeAlias, TypedDict, TypeVarTuple, Unpack, deprecated if sys.version_info >= (3, 9): __all__ = [ diff --git a/test_cases/stdlib/check_tkinter.py b/test_cases/stdlib/check_tkinter.py index 9e6b64d64c7b..61da56ea6df4 100644 --- a/test_cases/stdlib/check_tkinter.py +++ b/test_cases/stdlib/check_tkinter.py @@ -17,5 +17,6 @@ def custom_handler(exc: type[BaseException], val: BaseException, tb: types.Trace def foo(x: int, y: str) -> None: pass + root.after(1000, foo, 10, "lol") root.after(1000, foo, 10, 10) # type: ignore