From 41137ca5923c19eeedf13635e4b4ec55c5640754 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 18 Aug 2020 13:30:36 +0300 Subject: [PATCH 1/3] fix config method --- stdlib/3/tkinter/ttk.pyi | 106 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 5 deletions(-) diff --git a/stdlib/3/tkinter/ttk.pyi b/stdlib/3/tkinter/ttk.pyi index 564ddae3abc1..7ba4127f148e 100644 --- a/stdlib/3/tkinter/ttk.pyi +++ b/stdlib/3/tkinter/ttk.pyi @@ -234,7 +234,31 @@ class Entry(Widget, tkinter.Entry): ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @overload def configure(self, cnf: _EntryOptionName) -> Tuple[str, str, str, Any, Any]: ... - config = configure # type: ignore + # config must be copy/pasted, otherwise ttk.Entry().config is mypy error (don't know why) + @overload # type: ignore + def config( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: tkinter._Color = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + show: str = ..., + state: Literal["normal", "disabled", "readonly"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + width: int = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def config(self, cnf: _EntryOptionName) -> Tuple[str, str, str, Any, Any]: ... def cget(self, key: _EntryOptionName) -> Any: ... # type: ignore def bbox(self, index): ... def identify(self, x, y): ... @@ -316,7 +340,34 @@ class Combobox(Entry): ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @overload def configure(self, cnf: _ComboboxOptionName) -> Tuple[str, str, str, Any, Any]: ... - config = configure # type: ignore + # config must be copy/pasted, otherwise ttk.Combobox().config is mypy error (don't know why) + @overload # type: ignore + def config( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: tkinter._Color = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + height: int = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + postcommand: Union[Callable[[], None], str] = ..., + show: Any = ..., + state: Literal["normal", "readonly", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + values: tkinter._TkinterSequence[str] = ..., + width: int = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def config(self, cnf: _ComboboxOptionName) -> Tuple[str, str, str, Any, Any]: ... def cget(self, key: _ComboboxOptionName) -> Any: ... # type: ignore def current(self, newindex: Optional[Any] = ...): ... def set(self, value): ... @@ -638,7 +689,20 @@ class Panedwindow(Widget, tkinter.PanedWindow): ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @overload def configure(self, cnf: _PanedwindowOptionName) -> Tuple[str, str, str, Any, Any]: ... - config = configure # type: ignore + # config must be copy/pasted, otherwise ttk.Panedwindow().config is mypy error (don't know why) + @overload # type: ignore + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + cursor: tkinter._Cursor = ..., + height: int = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + width: int = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _PanedwindowOptionName) -> Tuple[str, str, str, Any, Any]: ... def cget(self, key: _PanedwindowOptionName) -> Any: ... # type: ignore forget: Any def insert(self, pos, child, **kw): ... @@ -798,7 +862,26 @@ class Scale(Widget, tkinter.Scale): ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @overload def configure(self, cnf: _ScaleOptionName) -> Tuple[str, str, str, Any, Any]: ... - config = configure # type: ignore + # config must be copy/pasted, otherwise ttk.Scale().config is mypy error (don't know why) + @overload # type: ignore + def config( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + command: Union[str, Callable[[str], None]] = ..., + cursor: tkinter._Cursor = ..., + from_: float = ..., + length: tkinter._ScreenUnits = ..., + orient: Literal["horizontal", "vertical"] = ..., + state: Any = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + to: float = ..., + value: float = ..., + variable: tkinter.DoubleVar = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def config(self, cnf: _ScaleOptionName) -> Tuple[str, str, str, Any, Any]: ... def cget(self, key: _ScaleOptionName) -> Any: ... # type: ignore def get(self, x: Optional[Any] = ..., y: Optional[Any] = ...): ... @@ -829,7 +912,20 @@ class Scrollbar(Widget, tkinter.Scrollbar): ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @overload def configure(self, cnf: _ScrollbarOptionName) -> Tuple[str, str, str, Any, Any]: ... - config = configure # type: ignore + # config must be copy/pasted, otherwise ttk.Scrollbar().config is mypy error (don't know why) + @overload # type: ignore + def config( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + command: Union[Callable[..., Optional[Tuple[float, float]]], str] = ..., + cursor: tkinter._Cursor = ..., + orient: Literal["horizontal", "vertical"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def config(self, cnf: _ScrollbarOptionName) -> Tuple[str, str, str, Any, Any]: ... def cget(self, key: _ScrollbarOptionName) -> Any: ... # type: ignore _SeparatorOptionName = Literal["class", "cursor", "orient", "style", "takefocus"] From 434df8c8ecd2bf3b926e08c4a6e671e10db184cf Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 18 Aug 2020 13:32:54 +0300 Subject: [PATCH 2/3] allow aliasing Tk.configure as Toplevel method --- stdlib/3/tkinter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/tkinter/__init__.pyi b/stdlib/3/tkinter/__init__.pyi index 5961265d52ea..4c1546894de2 100644 --- a/stdlib/3/tkinter/__init__.pyi +++ b/stdlib/3/tkinter/__init__.pyi @@ -549,7 +549,7 @@ class Tk(Misc, Wm): ) -> None: ... @overload def configure( - self, + self: Union[Tk, Toplevel], cnf: Optional[Dict[str, Any]] = ..., *, background: _Color = ..., From fdd2015d69ca5c9ab0960b527ff58332d733f2cf Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 18 Aug 2020 13:36:57 +0300 Subject: [PATCH 3/3] fix copy/pasta --- stdlib/3/tkinter/ttk.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/tkinter/ttk.pyi b/stdlib/3/tkinter/ttk.pyi index 7ba4127f148e..1535c2452054 100644 --- a/stdlib/3/tkinter/ttk.pyi +++ b/stdlib/3/tkinter/ttk.pyi @@ -691,7 +691,7 @@ class Panedwindow(Widget, tkinter.PanedWindow): def configure(self, cnf: _PanedwindowOptionName) -> Tuple[str, str, str, Any, Any]: ... # config must be copy/pasted, otherwise ttk.Panedwindow().config is mypy error (don't know why) @overload # type: ignore - def configure( + def config( self, cnf: Optional[Dict[str, Any]] = ..., *, @@ -702,7 +702,7 @@ class Panedwindow(Widget, tkinter.PanedWindow): width: int = ..., ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @overload - def configure(self, cnf: _PanedwindowOptionName) -> Tuple[str, str, str, Any, Any]: ... + def config(self, cnf: _PanedwindowOptionName) -> Tuple[str, str, str, Any, Any]: ... def cget(self, key: _PanedwindowOptionName) -> Any: ... # type: ignore forget: Any def insert(self, pos, child, **kw): ...