Skip to content

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