From ccb57e0a7536ce3ca0ecf32e322fd5328f6847ee Mon Sep 17 00:00:00 2001 From: ANSHUL SINGH <72524975+ekanshul@users.noreply.github.com> Date: Wed, 19 Aug 2026 21:32:02 +0530 Subject: [PATCH] [tkinter] Allow any return value for invalidcommand Tk only evaluates the invalidcommand (invcmd) script when validatecommand returns false and ignores whatever it returns, so Callable[[], bool] was too strict and rejected ordinary callbacks that return None. Widen it to Callable[[], object] on all Entry, Spinbox, ttk.Entry, ttk.Combobox and ttk.Spinbox sites. validatecommand keeps Callable[[], bool] because Tk does use its result. Closes python/typeshed#10578 Co-Authored-By: Claude Fable 5 --- stdlib/tkinter/__init__.pyi | 16 ++++++++-------- stdlib/tkinter/ttk.pyi | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index a33f30adcbb9..59cbc4401e51 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -2236,8 +2236,8 @@ class Entry(Widget, XView): insertofftime: int = 300, insertontime: int = 600, insertwidth: float | str = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = "", - invcmd: str | list[str] | tuple[str, ...] | Callable[[], bool] = "", # same as invalidcommand + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = "", + invcmd: str | list[str] | tuple[str, ...] | Callable[[], object] = "", # same as invalidcommand justify: Literal["left", "center", "right"] = "left", name: str = ..., readonlybackground: str = ..., @@ -2281,8 +2281,8 @@ class Entry(Widget, XView): insertofftime: int = ..., insertontime: int = ..., insertwidth: float | str = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., - invcmd: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., + invcmd: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., justify: Literal["left", "center", "right"] = ..., readonlybackground: str = ..., relief: Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] = ..., @@ -4123,8 +4123,8 @@ class Spinbox(Widget, XView): insertofftime: int = 300, insertontime: int = 600, insertwidth: float | str = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = "", - invcmd: str | list[str] | tuple[str, ...] | Callable[[], bool] = "", + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = "", + invcmd: str | list[str] | tuple[str, ...] | Callable[[], object] = "", justify: Literal["left", "center", "right"] = "left", name: str = ..., readonlybackground: str = ..., @@ -4181,8 +4181,8 @@ class Spinbox(Widget, XView): insertofftime: int = ..., insertontime: int = ..., insertwidth: float | str = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., - invcmd: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., + invcmd: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., justify: Literal["left", "center", "right"] = ..., readonlybackground: str = ..., relief: Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] = ..., diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 06d2be13dc28..bf184bc2e8f8 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -340,7 +340,7 @@ class Entry(Widget, tkinter.Entry): exportselection: bool = True, font: _FontDescription = "TkTextFont", foreground: str = "", - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = "", + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = "", justify: Literal["left", "center", "right"] = "left", name: str = ..., show: str = "", @@ -364,7 +364,7 @@ class Entry(Widget, tkinter.Entry): exportselection: bool = ..., font: _FontDescription = ..., foreground: str = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., justify: Literal["left", "center", "right"] = ..., show: str = ..., state: str = ..., @@ -390,7 +390,7 @@ class Entry(Widget, tkinter.Entry): exportselection: bool = ..., font: _FontDescription = ..., foreground: str = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., justify: Literal["left", "center", "right"] = ..., show: str = ..., state: str = ..., @@ -421,7 +421,7 @@ class Combobox(Entry): font: _FontDescription = ..., # undocumented foreground: str = ..., # undocumented height: int = 10, - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., # undocumented + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., # undocumented justify: Literal["left", "center", "right"] = "left", name: str = ..., postcommand: Callable[[], object] | str = "", @@ -448,7 +448,7 @@ class Combobox(Entry): font: _FontDescription = ..., foreground: str = ..., height: int = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., justify: Literal["left", "center", "right"] = ..., postcommand: Callable[[], object] | str = ..., show=..., @@ -477,7 +477,7 @@ class Combobox(Entry): font: _FontDescription = ..., foreground: str = ..., height: int = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., justify: Literal["left", "center", "right"] = ..., postcommand: Callable[[], object] | str = ..., show=..., @@ -1068,7 +1068,7 @@ class Spinbox(Entry): format: str = "", from_: float = 0, increment: float = 1, - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., # undocumented + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., # undocumented justify: Literal["left", "center", "right"] = ..., # undocumented name: str = ..., show=..., # undocumented @@ -1099,7 +1099,7 @@ class Spinbox(Entry): format: str = ..., from_: float = ..., increment: float = ..., - invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., + invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., justify: Literal["left", "center", "right"] = ..., show=..., state: str = ...,