Skip to content

tkinter: Use a TypeVarTuple in .after() and .after_idle() methods #11014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions stdlib/tkinter/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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, TypeVarTuple, Unpack, deprecated

if sys.version_info >= (3, 9):
__all__ = [
Expand Down Expand Up @@ -314,6 +314,8 @@ getdouble: Incomplete

def getboolean(s): ...

_Ts = TypeVarTuple("_Ts")

class _GridIndexInfo(TypedDict, total=False):
minsize: _ScreenUnits
pad: _ScreenUnits
Expand Down Expand Up @@ -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: ...
Expand Down
8 changes: 8 additions & 0 deletions test_cases/stdlib/check_tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ 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