Skip to content

tkinter.font.Font: make __getitem__ and cget behave the same #4899

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

Merged
merged 2 commits into from
Jan 4, 2021

Conversation

Akuli
Copy link
Collaborator

@Akuli Akuli commented Jan 4, 2021

#4891 replaced widget.cget(Literal) with widget.cget(str), making cget behave just like __getitem__. This is the same change for Font objects, except that if a known Literal is passed, then the return type is more specific than Any and that may help catch bugs.

Examples:

  • font.cget('size') has type int (not changed)
  • font['size'] has type int (previously Any)
  • After setting foo: str = 'size', font.cget(foo) has type Any (previously error)
  • After setting foo: str = 'size', font[foo] has type Any (not changed)

@Akuli
Copy link
Collaborator Author

Akuli commented Jan 4, 2021

Stubtest complains about how def __getitem__(self, option) and def __getitem__(self, key) differ. I think type checkers ignore that for __dunder__ methods (at least mypy), so I whitelisted it. If that's not acceptable, another alternative is to replace __getitem__ = cget with copy/pasta.

@srittau
Copy link
Collaborator

srittau commented Jan 4, 2021

In reality, dunder methods are position-only. We should probably change our stubs accordingly at some point.

@srittau srittau merged commit 7710191 into python:master Jan 4, 2021
@Akuli Akuli deleted the font-fix branch January 5, 2021 12:40
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