Skip to content

Commit 8c412e4

Browse files
Improve type annotations for Widget.instate to better represent implementation
1 parent 4edf5a6 commit 8c412e4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

stdlib/tkinter/ttk.pyi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import tkinter
44
from _typeshed import MaybeNone
55
from collections.abc import Callable, Iterable, Sequence
66
from tkinter.font import _FontDescription
7-
from typing import Any, Literal, TypedDict, overload, type_check_only
7+
from typing import Any, Literal, TypedDict, TypeVar, overload, type_check_only
88
from typing_extensions import Never, TypeAlias, Unpack
99

1010
__all__ = [
@@ -54,6 +54,9 @@ _Statespec: TypeAlias = tuple[Unpack[tuple[str, ...]], Any]
5454
_ImageStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], tkinter._Image | str]
5555
_VsapiStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], int]
5656

57+
P = ParamSpec("P")
58+
T = TypeVar("T")
59+
5760
class _Layout(TypedDict, total=False):
5861
side: Literal["left", "right", "top", "bottom"]
5962
sticky: str # consists of letters 'n', 's', 'w', 'e', may contain repeats, may be empty
@@ -203,9 +206,10 @@ class Style:
203206
class Widget(tkinter.Widget):
204207
def __init__(self, master: tkinter.Misc | None, widgetname: str | None, kw: dict[str, Any] | None = None) -> None: ...
205208
def identify(self, x: int, y: int) -> str: ...
206-
def instate(
207-
self, statespec: Sequence[str], callback: Callable[..., Any] | None = None, *args: Any, **kw: Any
208-
) -> bool | Any: ...
209+
@overload
210+
def instate(self, statespec: Sequence[str], callback: None = None) -> bool: ...
211+
@overload
212+
def instate(self, statespec: Sequence[str], callback: Callable[P, T], *args: P.args, **kw: P.kwargs) -> bool | T: ...
209213
def state(self, statespec: Sequence[str] | None = None) -> tuple[str, ...]: ...
210214

211215
class Button(Widget):

0 commit comments

Comments
 (0)