-
-
Notifications
You must be signed in to change notification settings - Fork 2k
make tkinter.Event generic and add missing type hints to bind methods #4347
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
Conversation
|
there's conversation related to this in #4200 |
|
Currently CI checks are failing because these overloads overlap: I believe |
|
As far as I understand, you would want to use the following overload (i.e. no default for @overload
def bind(self, sequence: Optional[str] = ..., func: str, add: Optional[bool] = ...) -> None: ...Since this isn't possible, you need to use two overloads: @overload
def bind(self, sequence: Optional[str], func: str, add: Optional[bool] = ...) -> None: ...
@overload
def bind(self, *, func: str, add: Optional[bool] = ...) -> None: ... |
…, except in ttk" This reverts commit 4f17386.
|
@Hawk777 What's your opinion on |
|
Personally, I like |
srittau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no experience with tk, but the changes look sensible to me.
tkinter.Event[tkinter.Entry]denotes an event coming from anEntrywidget (e.g. user typed text to entry or clicked the entry).Literal['break']orNone. At runtime, almost any return value is acceptable (more precisely, anything that could be converted to a Tcl object), and anything except the string'break'would be treated the same. This breaks code that declares the return type asOptional[str]. If this is too bad, I can changeLiteral['break']tostr.tkinter.Eventwithout specifying a widget type is supported for backwards compatibility, but unfortunately that's equivalent totkinter.Event[tkinter.Any]rather thantkinter.Event[tkinter.Misc], soevent.widgetwill in this case be Any-typed. It was previously typedMiscrather than any. This shouldn't cause backwards compatibility issues because nobody is using tkinter withmypy --strict(that just doesn't work with what's currently in typeshed).bind()return value and other arguments are no longerAnytyped.