FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make `tkinter.Event` equivalent to `tkinter.Event[tkinter.Misc]` by Akuli · Pull Request #14053 · python/typeshed · GitHub

Repository navigation

Make tkinter.Event equivalent to tkinter.Event[tkinter.Misc] - #14053

Merged
srittau merged 1 commit into
python:mainfrom
Akuli:tkinter-event-default
May 13, 2025
Merged

srittau merged 1 commit into
python:mainfrom
Akuli:tkinter-event-default

Conversation

Akuli commented May 13, 2025 •
edited
Loading

Copy link
Copy Markdown
Collaborator

A tkinter.Event represents something happening in a widget. The event's widget field is basically the widget that caused it. The somewhat misleadingly named Misc class means "any widget".

When writing an event handler function, you can specify the type of event.widget by using e.g. event: tkinter.Event[tkinter.Label]. Before this PR, it is required with strict type checker settings, and you get Any if you don't use it. With this PR, it is assumed to be Misc. This is suitable for event handlers that don't use the .widget field.

For example:

import tkinter

def handle_event(event: tkinter.Event) -> None:
    reveal_type(event.widget)

Mypy output before:

a.py:3: error: Missing type parameters for generic type "Event"  [type-arg]
a.py:4: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)

Mypy ouput with this PR:

a.py:4: note: Revealed type is "tkinter.Misc"
Success: no issues found in 1 source file

The only reason why I didn't use default=Misc initially is that the default parameter didn't exist at the time.

Copy link
Copy Markdown
Contributor

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

srittau merged commit 9589e36 into python:main May 13, 2025
mmingyu pushed a commit to mmingyu/typeshed that referenced this pull request May 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL