From b26326529890a361197da8e35a86d97d347453e2 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 18 Nov 2021 12:46:49 +0300 Subject: [PATCH 1/8] Now `add=` in `tkinter.pyi` can be `''` or `'+'` Refs #6332 Docs https://docs.python.org/3/library/tkinter.html#bindings-and-events --- stdlib/tkinter/__init__.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 829db6c012d6..0ac54ef6c4e0 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -338,12 +338,12 @@ class Misc: # binds do. The default value of func is not str. @overload def bind( - self, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: bool | None = ... + self, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: Literal['', '+'] | None = ... ) -> str: ... @overload - def bind(self, sequence: str | None, func: str, add: bool | None = ...) -> None: ... + def bind(self, sequence: str | None, func: str, add: Literal['', '+'] | None = ...) -> None: ... @overload - def bind(self, *, func: str, add: bool | None = ...) -> None: ... + def bind(self, *, func: str, add: Literal['', '+'] | None = ...) -> None: ... # There's no way to know what type of widget bind_all and bind_class # callbacks will get, so those are Misc. @overload From dd98140f2c4fdc0109bffe9a901cae03c5aabff0 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 18 Nov 2021 13:20:06 +0300 Subject: [PATCH 2/8] Update __init__.pyi --- stdlib/tkinter/__init__.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 0ac54ef6c4e0..dfacdafb91a8 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -338,12 +338,12 @@ class Misc: # binds do. The default value of func is not str. @overload def bind( - self, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: Literal['', '+'] | None = ... + self, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: Literal["", "+"] | None = ... ) -> str: ... @overload - def bind(self, sequence: str | None, func: str, add: Literal['', '+'] | None = ...) -> None: ... + def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | None = ...) -> None: ... @overload - def bind(self, *, func: str, add: Literal['', '+'] | None = ...) -> None: ... + def bind(self, *, func: str, add: Literal["", "+"] | None = ...) -> None: ... # There's no way to know what type of widget bind_all and bind_class # callbacks will get, so those are Misc. @overload @@ -847,12 +847,12 @@ class Widget(BaseWidget, Pack, Place, Grid): # widgets don't. @overload def bind( - self: _W, sequence: str | None = ..., func: Callable[[Event[_W]], Any] | None = ..., add: bool | None = ... + self: _W, sequence: str | None = ..., func: Callable[[Event[_W]], Any] | None = ..., add: Literal["", "+"] | None = ... ) -> str: ... @overload - def bind(self, sequence: str | None, func: str, add: bool | None = ...) -> None: ... + def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | None = ...) -> None: ... @overload - def bind(self, *, func: str, add: bool | None = ...) -> None: ... + def bind(self, *, func: str, add: Literal["", "+"] | None = ...) -> None: ... class Toplevel(BaseWidget, Wm): # Toplevel and Tk have the same options because they correspond to the same From dd21c213641156504e4c5def2441af8d547c13b1 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 18 Nov 2021 19:05:57 +0300 Subject: [PATCH 3/8] Update __init__.pyi --- stdlib/tkinter/__init__.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index dfacdafb91a8..79cedac91454 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -338,12 +338,12 @@ class Misc: # binds do. The default value of func is not str. @overload def bind( - self, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: Literal["", "+"] | None = ... + self, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: Literal["", "+"] | bool | None = ... ) -> str: ... @overload - def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | None = ...) -> None: ... + def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... @overload - def bind(self, *, func: str, add: Literal["", "+"] | None = ...) -> None: ... + def bind(self, *, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... # There's no way to know what type of widget bind_all and bind_class # callbacks will get, so those are Misc. @overload @@ -847,12 +847,12 @@ class Widget(BaseWidget, Pack, Place, Grid): # widgets don't. @overload def bind( - self: _W, sequence: str | None = ..., func: Callable[[Event[_W]], Any] | None = ..., add: Literal["", "+"] | None = ... + self: _W, sequence: str | None = ..., func: Callable[[Event[_W]], Any] | None = ..., add: Literal["", "+"] | bool | None = ... ) -> str: ... @overload - def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | None = ...) -> None: ... + def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... @overload - def bind(self, *, func: str, add: Literal["", "+"] | None = ...) -> None: ... + def bind(self, *, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... class Toplevel(BaseWidget, Wm): # Toplevel and Tk have the same options because they correspond to the same From 920e4df445e526bfec5ffd26a2f6903263c496fd Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 18 Nov 2021 19:18:48 +0300 Subject: [PATCH 4/8] Update __init__.pyi --- stdlib/tkinter/__init__.pyi | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 79cedac91454..6a64069bc79b 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -338,7 +338,10 @@ class Misc: # binds do. The default value of func is not str. @overload def bind( - self, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: Literal["", "+"] | bool | None = ... + self, + sequence: str | None = ..., + func: Callable[[Event[Misc]], Any] | None = ..., + add: Literal["", "+"] | bool | None = ..., ) -> str: ... @overload def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... @@ -847,7 +850,10 @@ class Widget(BaseWidget, Pack, Place, Grid): # widgets don't. @overload def bind( - self: _W, sequence: str | None = ..., func: Callable[[Event[_W]], Any] | None = ..., add: Literal["", "+"] | bool | None = ... + self: _W, + sequence: str | None = ..., + func: Callable[[Event[_W]], Any] | None = ..., + add: Literal["", "+"] | bool | None = ..., ) -> str: ... @overload def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... From 8d23eb5ebd8894c709c8510248274e8158526da9 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 18 Nov 2021 21:13:53 +0300 Subject: [PATCH 5/8] Update __init__.pyi --- stdlib/tkinter/__init__.pyi | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 6a64069bc79b..6b64b7942ff2 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -351,20 +351,27 @@ class Misc: # callbacks will get, so those are Misc. @overload def bind_all( - self, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: bool | None = ... + self, + sequence: str | None = ..., + func: Callable[[Event[Misc]], Any] | None = ..., + add: Literal["", "+"] | bool | None = ..., ) -> str: ... @overload - def bind_all(self, sequence: str | None, func: str, add: bool | None = ...) -> None: ... + def bind_all(self, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... @overload - def bind_all(self, *, func: str, add: bool | None = ...) -> None: ... + def bind_all(self, *, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... @overload def bind_class( - self, className: str, sequence: str | None = ..., func: Callable[[Event[Misc]], Any] | None = ..., add: bool | None = ... + self, + className: str, + sequence: str | None = ..., + func: Callable[[Event[Misc]], Any] | None = ..., + add: Literal["", "+"] | bool | None = ..., ) -> str: ... @overload - def bind_class(self, className: str, sequence: str | None, func: str, add: bool | None = ...) -> None: ... + def bind_class(self, className: str, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... @overload - def bind_class(self, className: str, *, func: str, add: bool | None = ...) -> None: ... + def bind_class(self, className: str, *, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... def unbind(self, sequence: str, funcid: str | None = ...) -> None: ... def unbind_all(self, sequence: str) -> None: ... def unbind_class(self, className: str, sequence: str) -> None: ... From 47e477204a79ec40fe7fe28bf650ccbc14e7153f Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 18 Nov 2021 21:25:16 +0300 Subject: [PATCH 6/8] Update __init__.pyi --- stdlib/tkinter/__init__.pyi | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 6b64b7942ff2..d9f1b18c7ebb 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -1142,12 +1142,12 @@ class Canvas(Widget, XView, YView): tagOrId: str | int, sequence: str | None = ..., func: Callable[[Event[Canvas]], Any] | None = ..., - add: bool | None = ..., + add: Literal["", "+"] | bool | None = ..., ) -> str: ... @overload - def tag_bind(self, tagOrId: str | int, sequence: str | None, func: str, add: bool | None = ...) -> None: ... + def tag_bind(self, tagOrId: str | int, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... @overload - def tag_bind(self, tagOrId: str | int, *, func: str, add: bool | None = ...) -> None: ... + def tag_bind(self, tagOrId: str | int, *, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... def tag_unbind(self, tagOrId: str | int, sequence: str, funcid: str | None = ...) -> None: ... def canvasx(self, screenx, gridspacing: Any | None = ...): ... def canvasy(self, screeny, gridspacing: Any | None = ...): ... @@ -2892,10 +2892,14 @@ class Text(Widget, XView, YView): # tag_bind stuff is very similar to Canvas @overload def tag_bind( - self, tagName: str, sequence: str | None, func: Callable[[Event[Text]], Any] | None, add: bool | None = ... + self, + tagName: str, + sequence: str | None, + func: Callable[[Event[Text]], Any] | None, + add: Literal["", "+"] | bool | None = ..., ) -> str: ... @overload - def tag_bind(self, tagName: str, sequence: str | None, func: str, add: bool | None = ...) -> None: ... + def tag_bind(self, tagName: str, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... def tag_unbind(self, tagName: str, sequence: str, funcid: str | None = ...) -> None: ... # allowing any string for cget instead of just Literals because there's no other way to look up tag options def tag_cget(self, tagName: str, option: str) -> Any: ... From 178c2788101e4e909f7ea0efe878921efd834c2b Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 18 Nov 2021 21:30:07 +0300 Subject: [PATCH 7/8] Update __init__.pyi --- stdlib/tkinter/__init__.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index d9f1b18c7ebb..04fe5c017930 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -1145,7 +1145,9 @@ class Canvas(Widget, XView, YView): add: Literal["", "+"] | bool | None = ..., ) -> str: ... @overload - def tag_bind(self, tagOrId: str | int, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... + def tag_bind( + self, tagOrId: str | int, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ..., + ) -> None: ... @overload def tag_bind(self, tagOrId: str | int, *, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ... def tag_unbind(self, tagOrId: str | int, sequence: str, funcid: str | None = ...) -> None: ... From 1276dc1abff9a64cf1cf53c82467c6883e32ed91 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 18 Nov 2021 21:32:08 +0300 Subject: [PATCH 8/8] Update __init__.pyi --- stdlib/tkinter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 04fe5c017930..bda37b406fc3 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -1146,7 +1146,7 @@ class Canvas(Widget, XView, YView): ) -> str: ... @overload def tag_bind( - self, tagOrId: str | int, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ..., + self, tagOrId: str | int, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = ... ) -> None: ... @overload def tag_bind(self, tagOrId: str | int, *, func: str, add: Literal["", "+"] | bool | None = ...) -> None: ...