From d3501e1794874d2e95be05dd8407766f7a6d9c8b Mon Sep 17 00:00:00 2001 From: Daniel Enesi <137162024+DanielOnGitHub17@users.noreply.github.com> Date: Sun, 28 Dec 2025 22:09:40 -0600 Subject: [PATCH 1/6] Improve type annotations for ttk.Widget --- stdlib/tkinter/ttk.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 1d72acd99512..caa982b971af 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -2,7 +2,7 @@ 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 @@ -201,10 +201,10 @@ 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): ... + def instate(self, statespec: Sequence[str], callback: Callable[..., Any] | None=None, *args: Any, **kw: Any) -> bool | Any: ... + def state(self, statespec: Sequence[str] | None=None) -> tuple[str, ...]: ... class Button(Widget): def __init__( From 4edf5a6a1719646a0f9a6d7cf01238f229ff0477 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Dec 2025 04:37:20 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tkinter/ttk.pyi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index caa982b971af..442db1bf3b3f 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -201,10 +201,12 @@ class Style: def theme_use(self, themename: None = None) -> str: ... class Widget(tkinter.Widget): - def __init__(self, master: tkinter.Misc | None, widgetname: str | None, kw: dict[str, Any] | None=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: Sequence[str], callback: Callable[..., Any] | None=None, *args: Any, **kw: Any) -> bool | Any: ... - def state(self, statespec: Sequence[str] | None=None) -> tuple[str, ...]: ... + def instate( + self, statespec: Sequence[str], callback: Callable[..., Any] | None = None, *args: Any, **kw: Any + ) -> bool | Any: ... + def state(self, statespec: Sequence[str] | None = None) -> tuple[str, ...]: ... class Button(Widget): def __init__( From 8c412e4d025a6d426341fd6c1aaff45731fff280 Mon Sep 17 00:00:00 2001 From: Daniel Enesi <137162024+DanielOnGitHub17@users.noreply.github.com> Date: Mon, 29 Dec 2025 14:32:39 -0600 Subject: [PATCH 3/6] Improve type annotations for Widget.instate to better represent implementation --- stdlib/tkinter/ttk.pyi | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 442db1bf3b3f..adc4e37bd2e2 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -4,7 +4,7 @@ import tkinter from _typeshed import MaybeNone from collections.abc import Callable, Iterable, Sequence from tkinter.font import _FontDescription -from typing import Any, Literal, TypedDict, overload, type_check_only +from typing import Any, Literal, TypedDict, TypeVar, overload, type_check_only from typing_extensions import Never, TypeAlias, Unpack __all__ = [ @@ -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 @@ -203,9 +206,10 @@ class Style: class Widget(tkinter.Widget): 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: Sequence[str], callback: Callable[..., Any] | None = None, *args: Any, **kw: Any - ) -> bool | Any: ... + @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) -> bool | T: ... def state(self, statespec: Sequence[str] | None = None) -> tuple[str, ...]: ... class Button(Widget): From 51b54aec6b207d2ffe213295db990c1c08c07f85 Mon Sep 17 00:00:00 2001 From: Daniel Enesi <137162024+DanielOnGitHub17@users.noreply.github.com> Date: Mon, 29 Dec 2025 14:38:01 -0600 Subject: [PATCH 4/6] Fix: ParamSpec import --- stdlib/tkinter/ttk.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index adc4e37bd2e2..8426c1fad101 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -4,7 +4,7 @@ import tkinter from _typeshed import MaybeNone from collections.abc import Callable, Iterable, Sequence from tkinter.font import _FontDescription -from typing import Any, Literal, TypedDict, TypeVar, overload, type_check_only +from typing import Any, Literal, ParamSpec, TypedDict, TypeVar, overload, type_check_only from typing_extensions import Never, TypeAlias, Unpack __all__ = [ From c825604c0662f0b957847d972d2df95b4228b565 Mon Sep 17 00:00:00 2001 From: Daniel Enesi <137162024+DanielOnGitHub17@users.noreply.github.com> Date: Mon, 29 Dec 2025 14:52:44 -0600 Subject: [PATCH 5/6] Fix: Make ParamSpec and TypeVar private --- stdlib/tkinter/ttk.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 8426c1fad101..368769332708 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -54,8 +54,8 @@ _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") +_P = ParamSpec("_P") +_T = TypeVar("_T") class _Layout(TypedDict, total=False): side: Literal["left", "right", "top", "bottom"] @@ -209,7 +209,7 @@ class Widget(tkinter.Widget): @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) -> bool | T: ... + def instate(self, statespec: Sequence[str], callback: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> bool | _T: ... def state(self, statespec: Sequence[str] | None = None) -> tuple[str, ...]: ... class Button(Widget): From 73e6b1fb76d56dbc2e7e8660caa47e35deade350 Mon Sep 17 00:00:00 2001 From: Daniel Enesi <137162024+DanielOnGitHub17@users.noreply.github.com> Date: Mon, 29 Dec 2025 15:06:56 -0600 Subject: [PATCH 6/6] Fix: Fallback for Python3.9 -> importing ParamSpec from typing_extensions instead --- stdlib/tkinter/ttk.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 368769332708..3a8d1643ff8c 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -4,8 +4,8 @@ import tkinter from _typeshed import MaybeNone from collections.abc import Callable, Iterable, Sequence from tkinter.font import _FontDescription -from typing import Any, Literal, ParamSpec, TypedDict, TypeVar, 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",