From c33586704b435c11ceeac7580ce79512745feeb2 Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Thu, 26 Jun 2025 19:21:21 +0100 Subject: [PATCH 01/11] Fix explicit occurrences of `Incomplete` in tkinter.ttk --- 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 50b9cd8f9bcd..52be9a04e6c7 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -1,6 +1,6 @@ import _tkinter import tkinter -from _typeshed import Incomplete, MaybeNone +from _typeshed import MaybeNone from collections.abc import Callable from tkinter.font import _FontDescription from typing import Any, Literal, TypedDict, overload @@ -49,7 +49,7 @@ _Padding: TypeAlias = ( _TtkCompound: TypeAlias = Literal["", "text", "image", tkinter._Compound] class Style: - master: Incomplete + master: tkinter.Misc tk: _tkinter.TkappType def __init__(self, master: tkinter.Misc | None = None) -> None: ... def configure(self, style, query_opt=None, **kw): ... @@ -615,7 +615,7 @@ class Panedwindow(Widget, tkinter.PanedWindow): ) -> dict[str, tuple[str, str, str, Any, Any]] | None: ... @overload def config(self, cnf: str) -> tuple[str, str, str, Any, Any]: ... - forget: Incomplete + forget = tkinter.PanedWindow.forget def insert(self, pos, child, **kw) -> None: ... def pane(self, pane, option=None, **kw): ... def sashpos(self, index, newpos=None): ... From 508e5786cd0e7b02ffa5b310a5091780f04a7876 Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Thu, 26 Jun 2025 23:25:03 +0100 Subject: [PATCH 02/11] Improve stubs for `setup_master``, `ttk.Style.configure`, `Style.map` --- stdlib/tkinter/ttk.pyi | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 52be9a04e6c7..c9946c4e97f3 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -3,8 +3,8 @@ import tkinter from _typeshed import MaybeNone from collections.abc import Callable from tkinter.font import _FontDescription -from typing import Any, Literal, TypedDict, overload -from typing_extensions import TypeAlias +from typing import Any, Literal, TypedDict, overload, Iterable +from typing_extensions import TypeAlias, Unpack __all__ = [ "Button", @@ -35,7 +35,7 @@ __all__ = [ ] def tclobjs_to_py(adict: dict[Any, Any]) -> dict[Any, Any]: ... -def setup_master(master=None): ... +def setup_master(master: tkinter.Misc | None = None): ... _Padding: TypeAlias = ( tkinter._ScreenUnits @@ -47,15 +47,26 @@ _Padding: TypeAlias = ( # from ttk_widget (aka ttk::widget) manual page, differs from tkinter._Compound _TtkCompound: TypeAlias = Literal["", "text", "image", tkinter._Compound] +# Last item (option value to apply) varies between different options so use Any. +# This doesn't have to be a tuple so also add a less precise Iterable option. +_Statespec: TypeAlias = tuple[Unpack[tuple[str, ...]], Any] | Iterable[str | Any] class Style: master: tkinter.Misc tk: _tkinter.TkappType def __init__(self, master: tkinter.Misc | None = None) -> None: ... - def configure(self, style, query_opt=None, **kw): ... - def map(self, style, query_opt=None, **kw): ... def lookup(self, style, option, state=None, default=None): ... def layout(self, style, layoutspec=None): ... + @overload + def configure(self, style: str) -> dict[str, Any]: ... + @overload + def configure(self, style: str, query_opt: str, **kw: Any) -> Any: ... + @overload + def configure(self, style: str, query_opt: None = None, **kw: Any) -> None: ... + @overload + def map(self, style: str, query_opt: str) -> _Statespec: ... + @overload + def map(self, style: str, **kw: Iterable[_Statespec]) -> dict[str, _Statespec]: ... def element_create(self, elementname, etype, *args, **kw) -> None: ... def element_names(self): ... def element_options(self, elementname): ... From 053a00a38d5aeadc67c448d3e39b25fd4302af64 Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sat, 28 Jun 2025 14:45:58 +0100 Subject: [PATCH 03/11] Finish types for ttk.Style --- stdlib/tkinter/ttk.pyi | 99 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index c9946c4e97f3..bd30342b4f6c 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -1,10 +1,11 @@ import _tkinter +import sys import tkinter -from _typeshed import MaybeNone +from _typeshed import MaybeNone, Incomplete from collections.abc import Callable from tkinter.font import _FontDescription from typing import Any, Literal, TypedDict, overload, Iterable -from typing_extensions import TypeAlias, Unpack +from typing_extensions import TypeAlias, Unpack, Never __all__ = [ "Button", @@ -47,18 +48,68 @@ _Padding: TypeAlias = ( # from ttk_widget (aka ttk::widget) manual page, differs from tkinter._Compound _TtkCompound: TypeAlias = Literal["", "text", "image", tkinter._Compound] + # Last item (option value to apply) varies between different options so use Any. -# This doesn't have to be a tuple so also add a less precise Iterable option. -_Statespec: TypeAlias = tuple[Unpack[tuple[str, ...]], Any] | Iterable[str | Any] +# It could also be any iterable with items matching the tuple, but that case +# hasn't been added here for consistency with _Padding above. +_Statespec: TypeAlias = tuple[Unpack[tuple[str, ...]], Any] +_ImageStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], tkinter._ImageSpec] +_VsapiStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], int] +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 + unit: Literal[0, 1] | bool + children: _LayoutSpec + # Note: there seem to be some other undocumented keys sometimes +# This could be any sequence when passed as a parameter but will always be a list when returned. +_LayoutSpec: TypeAlias = list[tuple[str, _Layout | None]] + +# Keep these in sync with the appropriate methods in Style +class _ElementCreateImageKwargs(TypedDict, total=False): + border: _Padding + height: tkinter._ScreenUnits + padding: _Padding + sticky: str + width: tkinter._ScreenUnits +_ElementCreateArgsCrossPlatform: TypeAlias = ( + # Could be any sequence here but types are not homogenous so just type it as tuple + tuple[Literal['image'], tkinter._ImageSpec, Unpack[tuple[_ImageStatespec, ...]], _ElementCreateImageKwargs] + | tuple[Literal['from'], str, str] | tuple[Literal['from'], str] # (fromelement is optional) +) +if sys.platform == "win32" and sys.version_info >= (3, 13): + class _ElementCreateVsapiKwargsPadding(TypedDict, total=False): + padding: _Padding + class _ElementCreateVsapiKwargsMargin(TypedDict, total=False): + padding: _Padding + class _ElementCreateVsapiKwargsSize(TypedDict): + width: tkinter._ScreenUnits + height: tkinter._ScreenUnits + _ElementCreateVsapiKwargsDict = ( + _ElementCreateVsapiKwargsPadding | _ElementCreateVsapiKwargsMargin | _ElementCreateVsapiKwargsSize) + _ElementCreateArgs: TypeAlias = ( + _ElementCreateArgsCrossPlatform + | tuple[Literal['vsapi'], str, int, _ElementCreateVsapiKwargsDict] + | tuple[Literal['vsapi'], str, int, _VsapiStatespec, _ElementCreateVsapiKwargsDict]) +else: + _ElementCreateArgs: TypeAlias = _ElementCreateArgsCrossPlatform +_ThemeSettingsValue = TypedDict( + '_ThemeSettingsValue', { + 'configure': dict[str, Any], + 'map': dict[str, Iterable[_Statespec]], + 'layout': _LayoutSpec, + 'element create': _ElementCreateArgs, + }, total=False +) +_ThemeSettings = dict[str, _ThemeSettingsValue] class Style: master: tkinter.Misc tk: _tkinter.TkappType def __init__(self, master: tkinter.Misc | None = None) -> None: ... - def lookup(self, style, option, state=None, default=None): ... - def layout(self, style, layoutspec=None): ... + # For these methods, values given vary between options. Returned values + # seem to be str, but this might not always be the case. @overload - def configure(self, style: str) -> dict[str, Any]: ... + def configure(self, style: str) -> dict[str, Any] | None: ... # Returns None if no configuration. @overload def configure(self, style: str, query_opt: str, **kw: Any) -> Any: ... @overload @@ -67,11 +118,35 @@ class Style: def map(self, style: str, query_opt: str) -> _Statespec: ... @overload def map(self, style: str, **kw: Iterable[_Statespec]) -> dict[str, _Statespec]: ... - def element_create(self, elementname, etype, *args, **kw) -> None: ... - def element_names(self): ... - def element_options(self, elementname): ... - def theme_create(self, themename, parent=None, settings=None) -> None: ... - def theme_settings(self, themename, settings) -> None: ... + def lookup(self, style: str, option: str, state: Iterable[str] | None = None, default: Any | None = None) -> Any: ... + @overload + def layout(self, style: str, layoutspec: _LayoutSpec) -> list[Never]: ... # Always seems to return an empty list + @overload + def layout(self, style: str, layoutspec: None = None) -> _LayoutSpec: ... + @overload + def element_create(self, elementname: str, etype: Literal['image'], __default_image: tkinter._ImageSpec, + *imagespec: _ImageStatespec, border: _Padding = ..., height: tkinter._ScreenUnits = ..., + padding: _Padding = ..., sticky: str = ..., width: tkinter._ScreenUnits = ...) -> None: ... + @overload + def element_create(self, elementname: str, etype: Literal['from'], __themename: str, __fromelement: str = ...) -> None: ... + if sys.platform == 'win32' and sys.version_info >= (3, 13): # and tk version >= 8.6 + # margin, padding, and (width + height) are mutually exclusive. width + # and height must either both be present or not present at all. Note: + # There are other undocumented options if you look at ttk's source code. + @overload + def element_create(self, elementname: str, etype: Literal['vsapi'], __class: str, __part: int, + __vs_statespec: _VsapiStatespec = (((), 1),), *, padding: _Padding = ...) -> None: ... + @overload + def element_create(self, elementname: str, etype: Literal['vsapi'], __class: str, __part: int, + __vs_statespec: _VsapiStatespec = (((), 1),), *, margin: _Padding = ...) -> None: ... + @overload + def element_create(self, elementname: str, etype: Literal['vsapi'], __class: str, __part: int, + __vs_statespec: _VsapiStatespec = (((), 1),), *, width: tkinter._ScreenUnits, + height: tkinter._ScreenUnits) -> None: ... + def element_names(self) -> tuple[str, ...]: ... + def element_options(self, elementname: str) -> tuple[str, ...]: ... + def theme_create(self, themename: str, parent: str = None, settings: _ThemeSettings | None = None) -> None: ... + def theme_settings(self, themename: str, settings: _ThemeSettings) -> None: ... def theme_names(self) -> tuple[str, ...]: ... @overload def theme_use(self, themename: str) -> None: ... From f6dd42894a25803bfa7c60060d55e794e6aaf6f7 Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sat, 28 Jun 2025 14:47:59 +0100 Subject: [PATCH 04/11] Fix unused import --- 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 bd30342b4f6c..9da2a73b3acf 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -1,11 +1,11 @@ import _tkinter import sys import tkinter -from _typeshed import MaybeNone, Incomplete +from _typeshed import MaybeNone from collections.abc import Callable from tkinter.font import _FontDescription -from typing import Any, Literal, TypedDict, overload, Iterable -from typing_extensions import TypeAlias, Unpack, Never +from typing import Any, Iterable, Literal, overload, TypedDict +from typing_extensions import Never, TypeAlias, Unpack __all__ = [ "Button", From 63f8e1e9e9d5eebb1945a2fd633f16069cd1c19a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 28 Jun 2025 13:54:45 +0000 Subject: [PATCH 05/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tkinter/ttk.pyi | 95 +++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 25 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 9da2a73b3acf..5c7e7a34462f 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -2,9 +2,9 @@ import _tkinter import sys import tkinter from _typeshed import MaybeNone -from collections.abc import Callable +from collections.abc import Callable, Iterable from tkinter.font import _FontDescription -from typing import Any, Iterable, Literal, overload, TypedDict +from typing import Any, Literal, TypedDict, overload from typing_extensions import Never, TypeAlias, Unpack __all__ = [ @@ -55,12 +55,14 @@ _TtkCompound: TypeAlias = Literal["", "text", "image", tkinter._Compound] _Statespec: TypeAlias = tuple[Unpack[tuple[str, ...]], Any] _ImageStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], tkinter._ImageSpec] _VsapiStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], int] + 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 unit: Literal[0, 1] | bool children: _LayoutSpec # Note: there seem to be some other undocumented keys sometimes + # This could be any sequence when passed as a parameter but will always be a list when returned. _LayoutSpec: TypeAlias = list[tuple[str, _Layout | None]] @@ -71,34 +73,43 @@ class _ElementCreateImageKwargs(TypedDict, total=False): padding: _Padding sticky: str width: tkinter._ScreenUnits + _ElementCreateArgsCrossPlatform: TypeAlias = ( # Could be any sequence here but types are not homogenous so just type it as tuple - tuple[Literal['image'], tkinter._ImageSpec, Unpack[tuple[_ImageStatespec, ...]], _ElementCreateImageKwargs] - | tuple[Literal['from'], str, str] | tuple[Literal['from'], str] # (fromelement is optional) + tuple[Literal["image"], tkinter._ImageSpec, Unpack[tuple[_ImageStatespec, ...]], _ElementCreateImageKwargs] + | tuple[Literal["from"], str, str] + | tuple[Literal["from"], str] # (fromelement is optional) ) if sys.platform == "win32" and sys.version_info >= (3, 13): class _ElementCreateVsapiKwargsPadding(TypedDict, total=False): padding: _Padding + class _ElementCreateVsapiKwargsMargin(TypedDict, total=False): padding: _Padding + class _ElementCreateVsapiKwargsSize(TypedDict): width: tkinter._ScreenUnits height: tkinter._ScreenUnits + _ElementCreateVsapiKwargsDict = ( - _ElementCreateVsapiKwargsPadding | _ElementCreateVsapiKwargsMargin | _ElementCreateVsapiKwargsSize) + _ElementCreateVsapiKwargsPadding | _ElementCreateVsapiKwargsMargin | _ElementCreateVsapiKwargsSize + ) _ElementCreateArgs: TypeAlias = ( _ElementCreateArgsCrossPlatform - | tuple[Literal['vsapi'], str, int, _ElementCreateVsapiKwargsDict] - | tuple[Literal['vsapi'], str, int, _VsapiStatespec, _ElementCreateVsapiKwargsDict]) + | tuple[Literal["vsapi"], str, int, _ElementCreateVsapiKwargsDict] + | tuple[Literal["vsapi"], str, int, _VsapiStatespec, _ElementCreateVsapiKwargsDict] + ) else: _ElementCreateArgs: TypeAlias = _ElementCreateArgsCrossPlatform _ThemeSettingsValue = TypedDict( - '_ThemeSettingsValue', { - 'configure': dict[str, Any], - 'map': dict[str, Iterable[_Statespec]], - 'layout': _LayoutSpec, - 'element create': _ElementCreateArgs, - }, total=False + "_ThemeSettingsValue", + { + "configure": dict[str, Any], + "map": dict[str, Iterable[_Statespec]], + "layout": _LayoutSpec, + "element create": _ElementCreateArgs, + }, + total=False, ) _ThemeSettings = dict[str, _ThemeSettingsValue] @@ -124,25 +135,59 @@ class Style: @overload def layout(self, style: str, layoutspec: None = None) -> _LayoutSpec: ... @overload - def element_create(self, elementname: str, etype: Literal['image'], __default_image: tkinter._ImageSpec, - *imagespec: _ImageStatespec, border: _Padding = ..., height: tkinter._ScreenUnits = ..., - padding: _Padding = ..., sticky: str = ..., width: tkinter._ScreenUnits = ...) -> None: ... + def element_create( + self, + elementname: str, + etype: Literal["image"], + __default_image: tkinter._ImageSpec, + *imagespec: _ImageStatespec, + border: _Padding = ..., + height: tkinter._ScreenUnits = ..., + padding: _Padding = ..., + sticky: str = ..., + width: tkinter._ScreenUnits = ..., + ) -> None: ... @overload - def element_create(self, elementname: str, etype: Literal['from'], __themename: str, __fromelement: str = ...) -> None: ... - if sys.platform == 'win32' and sys.version_info >= (3, 13): # and tk version >= 8.6 + def element_create(self, elementname: str, etype: Literal["from"], __themename: str, __fromelement: str = ...) -> None: ... + if sys.platform == "win32" and sys.version_info >= (3, 13): # and tk version >= 8.6 # margin, padding, and (width + height) are mutually exclusive. width # and height must either both be present or not present at all. Note: # There are other undocumented options if you look at ttk's source code. @overload - def element_create(self, elementname: str, etype: Literal['vsapi'], __class: str, __part: int, - __vs_statespec: _VsapiStatespec = (((), 1),), *, padding: _Padding = ...) -> None: ... + def element_create( + self, + elementname: str, + etype: Literal["vsapi"], + __class: str, + __part: int, + __vs_statespec: _VsapiStatespec = (((), 1),), + *, + padding: _Padding = ..., + ) -> None: ... @overload - def element_create(self, elementname: str, etype: Literal['vsapi'], __class: str, __part: int, - __vs_statespec: _VsapiStatespec = (((), 1),), *, margin: _Padding = ...) -> None: ... + def element_create( + self, + elementname: str, + etype: Literal["vsapi"], + __class: str, + __part: int, + __vs_statespec: _VsapiStatespec = (((), 1),), + *, + margin: _Padding = ..., + ) -> None: ... @overload - def element_create(self, elementname: str, etype: Literal['vsapi'], __class: str, __part: int, - __vs_statespec: _VsapiStatespec = (((), 1),), *, width: tkinter._ScreenUnits, - height: tkinter._ScreenUnits) -> None: ... + def element_create( + self, + elementname: str, + etype: Literal["vsapi"], + __class: str, + __part: int, + __vs_statespec: _VsapiStatespec = (((), 1),), + *, + width: tkinter._ScreenUnits, + height: tkinter._ScreenUnits, + ) -> None: ... + def element_names(self) -> tuple[str, ...]: ... def element_options(self, elementname: str) -> tuple[str, ...]: ... def theme_create(self, themename: str, parent: str = None, settings: _ThemeSettings | None = None) -> None: ... From f63bfb6b4e1a2f5b81699ebd4adee49feb5816fd Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sat, 28 Jun 2025 15:03:05 +0100 Subject: [PATCH 06/11] Fix pre-commit failures --- stdlib/tkinter/ttk.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 5c7e7a34462f..a68aad429cd7 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -91,7 +91,7 @@ if sys.platform == "win32" and sys.version_info >= (3, 13): width: tkinter._ScreenUnits height: tkinter._ScreenUnits - _ElementCreateVsapiKwargsDict = ( + _ElementCreateVsapiKwargsDict: TypeAlias = ( _ElementCreateVsapiKwargsPadding | _ElementCreateVsapiKwargsMargin | _ElementCreateVsapiKwargsSize ) _ElementCreateArgs: TypeAlias = ( @@ -101,7 +101,7 @@ if sys.platform == "win32" and sys.version_info >= (3, 13): ) else: _ElementCreateArgs: TypeAlias = _ElementCreateArgsCrossPlatform -_ThemeSettingsValue = TypedDict( +_ThemeSettingsValue: TypeAlias = TypedDict( "_ThemeSettingsValue", { "configure": dict[str, Any], @@ -111,7 +111,7 @@ _ThemeSettingsValue = TypedDict( }, total=False, ) -_ThemeSettings = dict[str, _ThemeSettingsValue] +_ThemeSettings: TypeAlias = dict[str, _ThemeSettingsValue] class Style: master: tkinter.Misc @@ -160,7 +160,7 @@ class Style: etype: Literal["vsapi"], __class: str, __part: int, - __vs_statespec: _VsapiStatespec = (((), 1),), + __vs_statespec: _VsapiStatespec = ..., *, padding: _Padding = ..., ) -> None: ... @@ -171,7 +171,7 @@ class Style: etype: Literal["vsapi"], __class: str, __part: int, - __vs_statespec: _VsapiStatespec = (((), 1),), + __vs_statespec: _VsapiStatespec = ..., *, margin: _Padding = ..., ) -> None: ... @@ -182,7 +182,7 @@ class Style: etype: Literal["vsapi"], __class: str, __part: int, - __vs_statespec: _VsapiStatespec = (((), 1),), + __vs_statespec: _VsapiStatespec = ..., *, width: tkinter._ScreenUnits, height: tkinter._ScreenUnits, From 03981fa75ae2c6a07c1e954fd1077df6d86dc57e Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sat, 28 Jun 2025 15:04:38 +0100 Subject: [PATCH 07/11] (Try to) Fix CI failures --- 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 a68aad429cd7..6c6a17aefbae 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -101,7 +101,7 @@ if sys.platform == "win32" and sys.version_info >= (3, 13): ) else: _ElementCreateArgs: TypeAlias = _ElementCreateArgsCrossPlatform -_ThemeSettingsValue: TypeAlias = TypedDict( +_ThemeSettingsValue = TypedDict( "_ThemeSettingsValue", { "configure": dict[str, Any], @@ -190,7 +190,7 @@ class Style: def element_names(self) -> tuple[str, ...]: ... def element_options(self, elementname: str) -> tuple[str, ...]: ... - def theme_create(self, themename: str, parent: str = None, settings: _ThemeSettings | None = None) -> None: ... + def theme_create(self, themename: str, parent: str | None = None, settings: _ThemeSettings | None = None) -> None: ... def theme_settings(self, themename: str, settings: _ThemeSettings) -> None: ... def theme_names(self) -> tuple[str, ...]: ... @overload From d3d3beb3f1020332a90799075484c4980706691e Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sat, 28 Jun 2025 15:12:09 +0100 Subject: [PATCH 08/11] Try to fix CI failures again --- 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 6c6a17aefbae..31b8c55ded1b 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -128,7 +128,7 @@ class Style: @overload def map(self, style: str, query_opt: str) -> _Statespec: ... @overload - def map(self, style: str, **kw: Iterable[_Statespec]) -> dict[str, _Statespec]: ... + def map(self, style: str, query_op: None = None, **kw: Iterable[_Statespec]) -> dict[str, _Statespec]: ... def lookup(self, style: str, option: str, state: Iterable[str] | None = None, default: Any | None = None) -> Any: ... @overload def layout(self, style: str, layoutspec: _LayoutSpec) -> list[Never]: ... # Always seems to return an empty list From 33f06c8ff47b46d5b707f39c2eb78fbeb1a5dc38 Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sat, 28 Jun 2025 16:22:04 +0100 Subject: [PATCH 09/11] Fix some more CI failures --- stdlib/tkinter/ttk.pyi | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 31b8c55ded1b..62982c7ec9b4 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -128,7 +128,7 @@ class Style: @overload def map(self, style: str, query_opt: str) -> _Statespec: ... @overload - def map(self, style: str, query_op: None = None, **kw: Iterable[_Statespec]) -> dict[str, _Statespec]: ... + def map(self, style: str, query_opt: None = None, **kw: Iterable[_Statespec]) -> dict[str, _Statespec]: ... def lookup(self, style: str, option: str, state: Iterable[str] | None = None, default: Any | None = None) -> Any: ... @overload def layout(self, style: str, layoutspec: _LayoutSpec) -> list[Never]: ... # Always seems to return an empty list @@ -139,7 +139,7 @@ class Style: self, elementname: str, etype: Literal["image"], - __default_image: tkinter._ImageSpec, + default_image: tkinter._ImageSpec, /, *imagespec: _ImageStatespec, border: _Padding = ..., height: tkinter._ScreenUnits = ..., @@ -148,7 +148,7 @@ class Style: width: tkinter._ScreenUnits = ..., ) -> None: ... @overload - def element_create(self, elementname: str, etype: Literal["from"], __themename: str, __fromelement: str = ...) -> None: ... + def element_create(self, elementname: str, etype: Literal["from"], themename: str, fromelement: str = ..., /) -> None: ... if sys.platform == "win32" and sys.version_info >= (3, 13): # and tk version >= 8.6 # margin, padding, and (width + height) are mutually exclusive. width # and height must either both be present or not present at all. Note: @@ -158,9 +158,9 @@ class Style: self, elementname: str, etype: Literal["vsapi"], - __class: str, - __part: int, - __vs_statespec: _VsapiStatespec = ..., + class_: str, + part: int, + vs_statespec: _VsapiStatespec = ..., /, *, padding: _Padding = ..., ) -> None: ... @@ -169,9 +169,9 @@ class Style: self, elementname: str, etype: Literal["vsapi"], - __class: str, - __part: int, - __vs_statespec: _VsapiStatespec = ..., + class_: str, + part: int, + vs_statespec: _VsapiStatespec = ..., /, *, margin: _Padding = ..., ) -> None: ... @@ -180,9 +180,9 @@ class Style: self, elementname: str, etype: Literal["vsapi"], - __class: str, - __part: int, - __vs_statespec: _VsapiStatespec = ..., + class_: str, + part: int, + vs_statespec: _VsapiStatespec = ..., /, *, width: tkinter._ScreenUnits, height: tkinter._ScreenUnits, From fe3f9f6331472eb9b33e9fdcad139ebbb2b89611 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 28 Jun 2025 15:24:26 +0000 Subject: [PATCH 10/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- 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 62982c7ec9b4..d6c9ceed109c 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -139,7 +139,8 @@ class Style: self, elementname: str, etype: Literal["image"], - default_image: tkinter._ImageSpec, /, + default_image: tkinter._ImageSpec, + /, *imagespec: _ImageStatespec, border: _Padding = ..., height: tkinter._ScreenUnits = ..., @@ -160,7 +161,8 @@ class Style: etype: Literal["vsapi"], class_: str, part: int, - vs_statespec: _VsapiStatespec = ..., /, + vs_statespec: _VsapiStatespec = ..., + /, *, padding: _Padding = ..., ) -> None: ... @@ -171,7 +173,8 @@ class Style: etype: Literal["vsapi"], class_: str, part: int, - vs_statespec: _VsapiStatespec = ..., /, + vs_statespec: _VsapiStatespec = ..., + /, *, margin: _Padding = ..., ) -> None: ... @@ -182,7 +185,8 @@ class Style: etype: Literal["vsapi"], class_: str, part: int, - vs_statespec: _VsapiStatespec = ..., /, + vs_statespec: _VsapiStatespec = ..., + /, *, width: tkinter._ScreenUnits, height: tkinter._ScreenUnits, From c86e49931e093d6b9aadcc75d8588908a2c30274 Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sat, 28 Jun 2025 18:57:44 +0100 Subject: [PATCH 11/11] Try to work around stubtest error --- stdlib/tkinter/ttk.pyi | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index d6c9ceed109c..149a08faa034 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -139,8 +139,14 @@ class Style: self, elementname: str, etype: Literal["image"], - default_image: tkinter._ImageSpec, - /, + # This is technically positional-only and others above are positional-or-keyword. + # But as this isn't optional, the ones above must also be positional-only. + # However, this is inconsistent with the implementation (as it technically has the ones above as positional-or-keyword + # and this one in *args and then it checks that this is present but to get this into the *args, the previous 2 must + # also be given positionally so are in practise positional-only). Therefore, stubtest complains. + # (I'm not sure if this is the best way to handle this - ignoring the + # stubtest error would result in stubs that actually match the code) + _default_image: tkinter._ImageSpec, *imagespec: _ImageStatespec, border: _Padding = ..., height: tkinter._ScreenUnits = ..., @@ -159,10 +165,9 @@ class Style: self, elementname: str, etype: Literal["vsapi"], - class_: str, - part: int, - vs_statespec: _VsapiStatespec = ..., - /, + _class: str, + _part: int, + _vs_statespec: _VsapiStatespec = ..., *, padding: _Padding = ..., ) -> None: ... @@ -171,10 +176,9 @@ class Style: self, elementname: str, etype: Literal["vsapi"], - class_: str, - part: int, - vs_statespec: _VsapiStatespec = ..., - /, + _class: str, + _part: int, + _vs_statespec: _VsapiStatespec = ..., *, margin: _Padding = ..., ) -> None: ... @@ -183,10 +187,9 @@ class Style: self, elementname: str, etype: Literal["vsapi"], - class_: str, - part: int, - vs_statespec: _VsapiStatespec = ..., - /, + _class: str, + _part: int, + _vs_statespec: _VsapiStatespec = ..., *, width: tkinter._ScreenUnits, height: tkinter._ScreenUnits,