You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tkinter.Event is typed as generic but implementation isn't subscriptable #12591
Not sure if this is intended behaviour (I assume it isn't) but right now type checkers can only be satisfied if doing from __future__ import annotations or putting tk.Event[...] in quotes
CPython maintainers (I think Guido) have mentioned making tkinter.Event generic at runtime, but they never did it. Maybe you could submit a PR there? :)
The reason tkinter.Event is generic is that tkinter.Event[tkinter.Label] is an event coming from clicking (or otherwise interacting with) a tkinter.Label widget, and when you access event.widget, the type checker knows it is a label and acts accordingly.
Activity
srittau commentedon Aug 25, 2024
This is a common issue with type stubs and intended. We prefer to use generics if it improves type checking even if the implementation is not generic.
Akuli commentedon Aug 25, 2024
CPython maintainers (I think Guido) have mentioned making
tkinter.Eventgeneric at runtime, but they never did it. Maybe you could submit a PR there? :)The reason
tkinter.Eventis generic is thattkinter.Event[tkinter.Label]is an event coming from clicking (or otherwise interacting with) atkinter.Labelwidget, and when you accessevent.widget, the type checker knows it is a label and acts accordingly.yowoda commentedon Aug 25, 2024
Sure, once I'm free the next few days I can definitely submit a PR