Skip to content
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

Add a couple missing tkinter things #13149

Merged
merged 8 commits into from
Nov 29, 2024
Merged

Add a couple missing tkinter things #13149

merged 8 commits into from
Nov 29, 2024

Conversation

tungol
Copy link
Contributor

@tungol tungol commented Nov 28, 2024

The comment said this will cause lots of mypy problems, let's see what.

The comment said this will cause lots of mypy problems, let's see what.

This comment has been minimized.

@tungol
Copy link
Contributor Author

tungol commented Nov 28, 2024

I see; the problem is that config also exists as an alias of configure in the subclasses, and the signatures don't match. Mypy understands methods being overridden a lot better than it understands assignments being overridden. Hopefully this fixes it.

This comment has been minimized.

@tungol
Copy link
Contributor Author

tungol commented Nov 28, 2024

Too bad. Mypy and pyright have different behavior here. Given this:

label = tkinter.Label()
reveal_type(label.config)

Mypy shows the more specific overload that created on tkinter.Label:

stdlib/@tests/test_cases/check_tkinter.py:34: note: Revealed type is "Overload(def (cnf: Union[builtins.dict[builtins.str, Any], None] =, *, activebackground: builtins.str =, activeforeground: builtins.str =, anchor: Union[Literal['nw'], Literal['n'], Literal['ne'], Literal['w'], Literal['center'], Literal['e'], Literal['sw'], Literal['s'], Literal['se']] =, background: builtins.str =, bd: Union[builtins.str, builtins.float] =, bg: builtins.str =, bitmap: builtins.str =, border: Union[builtins.str, builtins.float] =, borderwidth: Union[builtins.str, builtins.float] =, compound: Union[Literal['top'], Literal['left'], Literal['center'], Literal['right'], Literal['bottom'], Literal['none']] =, cursor: Union[builtins.str, tuple[builtins.str], tuple[builtins.str, builtins.str], tuple[builtins.str, builtins.str, builtins.str], tuple[builtins.str, builtins.str, builtins.str, builtins.str]] =, disabledforeground: builtins.str =, fg: builtins.str =, font: Union[builtins.str, tkinter.font.Font, builtins.list[Any], tuple[builtins.str], tuple[builtins.str, builtins.int], tuple[builtins.str, builtins.int, builtins.str], tuple[builtins.str, builtins.int, Union[builtins.list[builtins.str], builtins.tuple[builtins.str, ...]]], _tkinter.Tcl_Obj] =, foreground: builtins.str =, height: Union[builtins.str, builtins.float] =, highlightbackground: builtins.str =, highlightcolor: builtins.str =, highlightthickness: Union[builtins.str, builtins.float] =, image: Union[tkinter._Image, builtins.str] =, justify: Union[Literal['left'], Literal['center'], Literal['right']] =, padx: Union[builtins.str, builtins.float] =, pady: Union[builtins.str, builtins.float] =, relief: Union[Literal['raised'], Literal['sunken'], Literal['flat'], Literal['ridge'], Literal['solid'], Literal['groove']] =, state: Union[Literal['normal'], Literal['active'], Literal['disabled']] =, takefocus: Union[builtins.bool, Literal[0], Literal[1], Literal[''], def (builtins.str) -> Union[builtins.bool, None]] =, text: Union[builtins.float, builtins.str] =, textvariable: tkinter.Variable =, underline: builtins.int =, width: Union[builtins.str, builtins.float] =, wraplength: Union[builtins.str, builtins.float] =) -> Union[builtins.dict[builtins.str, tuple[builtins.str, builtins.str, builtins.str, Any, Any]], None], def (cnf: builtins.str) -> tuple[builtins.str, builtins.str, builtins.str, Any, Any])"

but pyright stays with the base class annotation and says:

stdlib/@tests/test_cases/check_tkinter.py:34:13 - information: Type of "label.config" is "(...) -> Any"

Given that, I don't know if there's a way to add Misc.config without causing problems.

This comment has been minimized.

@JelleZijlstra JelleZijlstra requested a review from Akuli November 28, 2024 15:02

This comment has been minimized.

stdlib/tkinter/font.pyi Outdated Show resolved Hide resolved
not sure if this actually matters to any type checkers?
Seems more accurate though.
@Akuli
Copy link
Collaborator

Akuli commented Nov 28, 2024

not sure if this actually matters to any type checkers? Seems more accurate though.

It doesn't, and we prefer leaving out the = .... Apparently we don't have a linter rule for that.

This comment has been minimized.

@tungol
Copy link
Contributor Author

tungol commented Nov 28, 2024

Good to know

Copy link
Contributor

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

@Akuli Akuli changed the title add missing tkinter things Add a couple missing tkinter things Nov 29, 2024
Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

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

Thanks!

@Akuli Akuli merged commit 2ccc53b into python:main Nov 29, 2024
63 checks passed
@tungol tungol deleted the tkinter branch November 29, 2024 01:16
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