Skip to content

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

This comment has been minimized.

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should just ignore the stubtest error.

@Akuli Akuli self-assigned this Jun 29, 2025
@Akuli
Copy link
Collaborator

Akuli commented Aug 24, 2025

Sorry about taking so long to get to this. First I was going to go through this in full detail, but eventually I realized I don't know anywhere near enough about ttk to do that.

I'm planning to trust you that this is correct enough, and just merge once CI is green.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "description", "name"  [misc]
+ discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "name", "description"  [misc]
- discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "description", "name"  [misc]
+ discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "name", "description"  [misc]
- discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
+ discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
- discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
+ discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
- discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
+ discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
- discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
+ discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
- discord/ext/commands/bot.py:290: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
+ discord/ext/commands/bot.py:290: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
- discord/ext/commands/bot.py:314: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
+ discord/ext/commands/bot.py:314: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]

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.

3 participants