From cad0c04ec092ff7a68b01b406a54ad749752c625 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 10 Nov 2023 20:18:25 +0200 Subject: [PATCH] tkinter: Require passing in a callback function to `.after()` (#11013) --- stdlib/tkinter/__init__.pyi | 5 ++--- tests/stubtest_allowlists/py3_common.txt | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 3f594bb95..d0eb97aa5 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -347,9 +347,8 @@ class Misc: def tk_focusFollowsMouse(self) -> None: ... def tk_focusNext(self) -> Misc | None: ... def tk_focusPrev(self) -> Misc | None: ... - @overload - def after(self, ms: int, func: None = None) -> None: ... - @overload + # .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: ... # after_idle is essentially partialmethod(after, "idle") def after_idle(self, func: Callable[..., object], *args: Any) -> str: ... diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 4c414b2bd..dc12c0f43 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -123,6 +123,7 @@ tkinter.simpledialog.TkVersion tkinter.tix.[A-Z_]+ tkinter.tix.TclVersion tkinter.tix.TkVersion +tkinter.Misc.after # we intentionally don't allow everything that "works" at runtime traceback.TracebackException.from_exception # explicitly expanding arguments going into TracebackException __init__ typing(_extensions)?\.IO\.__next__ # Added because IO streams are iterable. See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3 typing.type_check_only # typing decorator that is not available at runtime