Skip to content

[tkinter.ttk] Added type annotations for Style, fix some other incomplete parts #14348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
31 changes: 17 additions & 14 deletions stdlib/tkinter/ttk.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda awkward but you could do *imagespec: *tuple[tkinter._ImageSpec, *tuple[_ImageStatespec, ...]]. Not sure if this would be problematic to use though for code completion though.

border: _Padding = ...,
height: tkinter._ScreenUnits = ...,
Expand All @@ -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: ...
Expand All @@ -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: ...
Expand All @@ -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,
Expand Down
Loading