Skip to content

Commit ccb57e0

Browse files
ekanshulclaude
andcommitted
[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 #10578 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e8b9e19 commit ccb57e0

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

stdlib/tkinter/__init__.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,8 +2236,8 @@ class Entry(Widget, XView):
22362236
insertofftime: int = 300,
22372237
insertontime: int = 600,
22382238
insertwidth: float | str = ...,
2239-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = "",
2240-
invcmd: str | list[str] | tuple[str, ...] | Callable[[], bool] = "", # same as invalidcommand
2239+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = "",
2240+
invcmd: str | list[str] | tuple[str, ...] | Callable[[], object] = "", # same as invalidcommand
22412241
justify: Literal["left", "center", "right"] = "left",
22422242
name: str = ...,
22432243
readonlybackground: str = ...,
@@ -2281,8 +2281,8 @@ class Entry(Widget, XView):
22812281
insertofftime: int = ...,
22822282
insertontime: int = ...,
22832283
insertwidth: float | str = ...,
2284-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
2285-
invcmd: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
2284+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
2285+
invcmd: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
22862286
justify: Literal["left", "center", "right"] = ...,
22872287
readonlybackground: str = ...,
22882288
relief: Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] = ...,
@@ -4123,8 +4123,8 @@ class Spinbox(Widget, XView):
41234123
insertofftime: int = 300,
41244124
insertontime: int = 600,
41254125
insertwidth: float | str = ...,
4126-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = "",
4127-
invcmd: str | list[str] | tuple[str, ...] | Callable[[], bool] = "",
4126+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = "",
4127+
invcmd: str | list[str] | tuple[str, ...] | Callable[[], object] = "",
41284128
justify: Literal["left", "center", "right"] = "left",
41294129
name: str = ...,
41304130
readonlybackground: str = ...,
@@ -4181,8 +4181,8 @@ class Spinbox(Widget, XView):
41814181
insertofftime: int = ...,
41824182
insertontime: int = ...,
41834183
insertwidth: float | str = ...,
4184-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
4185-
invcmd: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
4184+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
4185+
invcmd: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
41864186
justify: Literal["left", "center", "right"] = ...,
41874187
readonlybackground: str = ...,
41884188
relief: Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] = ...,

stdlib/tkinter/ttk.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class Entry(Widget, tkinter.Entry):
340340
exportselection: bool = True,
341341
font: _FontDescription = "TkTextFont",
342342
foreground: str = "",
343-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = "",
343+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = "",
344344
justify: Literal["left", "center", "right"] = "left",
345345
name: str = ...,
346346
show: str = "",
@@ -364,7 +364,7 @@ class Entry(Widget, tkinter.Entry):
364364
exportselection: bool = ...,
365365
font: _FontDescription = ...,
366366
foreground: str = ...,
367-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
367+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
368368
justify: Literal["left", "center", "right"] = ...,
369369
show: str = ...,
370370
state: str = ...,
@@ -390,7 +390,7 @@ class Entry(Widget, tkinter.Entry):
390390
exportselection: bool = ...,
391391
font: _FontDescription = ...,
392392
foreground: str = ...,
393-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
393+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
394394
justify: Literal["left", "center", "right"] = ...,
395395
show: str = ...,
396396
state: str = ...,
@@ -421,7 +421,7 @@ class Combobox(Entry):
421421
font: _FontDescription = ..., # undocumented
422422
foreground: str = ..., # undocumented
423423
height: int = 10,
424-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., # undocumented
424+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., # undocumented
425425
justify: Literal["left", "center", "right"] = "left",
426426
name: str = ...,
427427
postcommand: Callable[[], object] | str = "",
@@ -448,7 +448,7 @@ class Combobox(Entry):
448448
font: _FontDescription = ...,
449449
foreground: str = ...,
450450
height: int = ...,
451-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
451+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
452452
justify: Literal["left", "center", "right"] = ...,
453453
postcommand: Callable[[], object] | str = ...,
454454
show=...,
@@ -477,7 +477,7 @@ class Combobox(Entry):
477477
font: _FontDescription = ...,
478478
foreground: str = ...,
479479
height: int = ...,
480-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
480+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
481481
justify: Literal["left", "center", "right"] = ...,
482482
postcommand: Callable[[], object] | str = ...,
483483
show=...,
@@ -1068,7 +1068,7 @@ class Spinbox(Entry):
10681068
format: str = "",
10691069
from_: float = 0,
10701070
increment: float = 1,
1071-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ..., # undocumented
1071+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ..., # undocumented
10721072
justify: Literal["left", "center", "right"] = ..., # undocumented
10731073
name: str = ...,
10741074
show=..., # undocumented
@@ -1099,7 +1099,7 @@ class Spinbox(Entry):
10991099
format: str = ...,
11001100
from_: float = ...,
11011101
increment: float = ...,
1102-
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], bool] = ...,
1102+
invalidcommand: str | list[str] | tuple[str, ...] | Callable[[], object] = ...,
11031103
justify: Literal["left", "center", "right"] = ...,
11041104
show=...,
11051105
state: str = ...,

0 commit comments

Comments
 (0)