Skip to content

Conversation

@Akuli
Copy link
Collaborator

@Akuli Akuli commented Jan 2, 2021

Fixes #4889

Using Literal in cget was the most controversial part of #4363. By instead making cget and __getitem__ behave in exactly the same way, we can put cget to Misc, the base class that all widgets inherit from. This is also how it's actually done in tkinter/__init__.py. Now any object with type Misc has a .cget() method as expected.

I also tried to do the same thing with the configure() method, but that's not perfect:

  • There are two ways to call configure(), and I could only get one of them to work in Misc. The other one takes widget-specific keyword arguments, and I don't know what should correspond with that in the Misc base class. I tried **kw: Any, but that wasn't compatible with the widget-specific configure() methods with specific options.
  • config is an alias for configure, and trying to add it to Misc (with def or with config = configure) creates mypy errors for some reason.

@Akuli
Copy link
Collaborator Author

Akuli commented Jan 2, 2021

Replacing these Literals with str shouldn't cause mypy to miss much more errors. By far the most common thing to do with a widget is changing an option with widget.config(option=value), and that's completely unaffected by this PR.

@JelleZijlstra JelleZijlstra merged commit bc1fe54 into python:master Jan 4, 2021
@Akuli Akuli deleted the tkinter-no-literal 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.

tkinter Widget do not accept .cget

2 participants