Skip to content

add types to tkinter invoke methods #5582

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
Jun 6, 2021
Merged

add types to tkinter invoke methods #5582

merged 2 commits into from
Jun 6, 2021

Conversation

Akuli
Copy link
Collaborator

@Akuli Akuli commented Jun 6, 2021

Most invoke methods return whatever the corresponding command of the widget returns, but passed through Tcl. So ints and strings and a few other things are returned as is, but everything else (such as collections.deque) becomes strings:

>>> import collections, tkinter
>>> b = tkinter.Button()
>>> b.invoke()
''
>>> b['command'] = lambda: 123
>>> b.invoke()
123
>>> b['command'] = lambda: collections.deque([1, 2, 3])
>>> b.invoke()
'deque([1, 2, 3])'

This doesn't apply to tkinter.Spinbox. I couldn't get it to return non-empty strings even by setting a custom command. The Tcl documentation doesn't mention anything about its return value, so it makes sense that it is always the empty string; it's similar to None as the default return value in Python.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2021

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

porcupine (https://github.com/Akuli/porcupine.git)
+ porcupine/utils.py:694: error: unused "type: ignore" comment

@srittau srittau merged commit 4b66a9c into python:master Jun 6, 2021
@Akuli Akuli deleted the invoke branch June 6, 2021 20:34
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