Improve type annotations for ttk.Widget (#15189)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Daniel Enesi
2026-01-02 04:18:17 -06:00
committed by GitHub
parent d1d5fe5866
commit eb347f3a1c
+14 -6
View File
@@ -2,10 +2,10 @@ import _tkinter
import sys
import tkinter
from _typeshed import MaybeNone
from collections.abc import Callable, Iterable
from collections.abc import Callable, Iterable, Sequence
from tkinter.font import _FontDescription
from typing import Any, Literal, TypedDict, overload, type_check_only
from typing_extensions import Never, TypeAlias, Unpack
from typing import Any, Literal, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import Never, ParamSpec, TypeAlias, Unpack
__all__ = [
"Button",
@@ -54,6 +54,9 @@ _Statespec: TypeAlias = tuple[Unpack[tuple[str, ...]], Any]
_ImageStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], tkinter._Image | str]
_VsapiStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], int]
_P = ParamSpec("_P")
_T = TypeVar("_T")
class _Layout(TypedDict, total=False):
side: Literal["left", "right", "top", "bottom"]
sticky: str # consists of letters 'n', 's', 'w', 'e', may contain repeats, may be empty
@@ -201,10 +204,15 @@ class Style:
def theme_use(self, themename: None = None) -> str: ...
class Widget(tkinter.Widget):
def __init__(self, master: tkinter.Misc | None, widgetname, kw=None) -> None: ...
def __init__(self, master: tkinter.Misc | None, widgetname: str | None, kw: dict[str, Any] | None = None) -> None: ...
def identify(self, x: int, y: int) -> str: ...
def instate(self, statespec, callback=None, *args, **kw): ...
def state(self, statespec=None): ...
@overload
def instate(self, statespec: Sequence[str], callback: None = None) -> bool: ...
@overload
def instate(
self, statespec: Sequence[str], callback: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs
) -> Literal[False] | _T: ...
def state(self, statespec: Sequence[str] | None = None) -> tuple[str, ...]: ...
class Button(Widget):
def __init__(