Thanks to visit codestin.com
Credit goes to github.com

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

Conversation

MarcellPerger1
Copy link
Contributor

  • Added type annotations for methods in tkinter.ttk.Style
  • 2 other functions improved (setup_master, Panedwindow.forget)

This comment has been minimized.

This comment has been minimized.

@MarcellPerger1
Copy link
Contributor Author

Is this a stubtest bug? It says

error: tkinter.ttk.Style.element_create is inconsistent, stub argument "elementname" has a default value but runtime argument does not
Stub: in file /home/runner/work/typeshed/typeshed/stdlib/tkinter/ttk.pyi:137

But on line 137, it has no default argument...
https://github.com/MarcellPerger1/typeshed/blob/c86e49931e093d6b9aadcc75d8588908a2c30274/stdlib/tkinter/ttk.pyi#L137-L158

It also seems to concatenate the overloaded functions' signatures together as it infers the signatue in the stub to be:

Inferred signature: def (self: tkinter.ttk.Style, elementname: builtins.str = ..., elementname: builtins.str = ..., etype: Literal['image'] = ..., etype: Literal['from'] = ..., _default_image: Union[tkinter._Image, builtins.str] = ..., themename: builtins.str = ..., fromelement: builtins.str = ..., *imagespec, border: Union[builtins.str, builtins.float, tuple[Union[builtins.str, builtins.float]], tuple[Union[builtins.str, builtins.float], Union[builtins.str, builtins.float]], tuple[Union[builtins.str, builtins.float], Union[builtins.str, builtins.float], Union[builtins.str, builtins.float]], tuple[Union[builtins.str, builtins.float], Union[builtins.str, builtins.float], Union[builtins.str, builtins.float], Union[builtins.str, builtins.float]]] = ..., height: Union[builtins.str, builtins.float] = ..., padding: Union[builtins.str, builtins.float, tuple[Union[builtins.str, builtins.float]], tuple[Union[builtins.str, builtins.float], Union[builtins.str, builtins.float]], tuple[Union[builtins.str, builtins.float], Union[builtins.str, builtins.float], Union[builtins.str, builtins.float]], tuple[Union[builtins.str, builtins.float], Union[builtins.str, builtins.float], Union[builtins.str, builtins.float], Union[builtins.str, builtins.float]]] = ..., sticky: builtins.str = ..., width: Union[builtins.str, builtins.float] = ...)

elementname appears twice after each other, there's two separate etype arguments... I have no clue what's going on here, but IMHO it doesn't look like the intended behavior

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@MarcellPerger1
Copy link
Contributor Author

For the pre-commit.ci failure, I have no clue why flake8 isn't recognizing the usage of _ElementCreateArgs on line 110

stdlib/tkinter/ttk.pyi:97:5: Y047 Type alias "_ElementCreateArgs" is not used

# 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants