Use typeshed.Incomplete and object instead of Any in tkinter stubs (#8458)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Akuli
2022-08-02 22:10:25 +03:00
committed by GitHub
parent 1dc1c91429
commit 5e5f3b4ecc
10 changed files with 230 additions and 218 deletions

View File

@@ -1,6 +1,7 @@
import _tkinter
import sys
import tkinter
from _typeshed import Incomplete
from collections.abc import Callable
from tkinter.font import _FontDescription
from typing import Any, overload
@@ -35,23 +36,23 @@ __all__ = [
]
def tclobjs_to_py(adict: dict[Any, Any]) -> dict[Any, Any]: ...
def setup_master(master: Any | None = ...): ...
def setup_master(master: Incomplete | None = ...): ...
# from ttk_widget (aka ttk::widget) manual page, differs from tkinter._Compound
_TtkCompound: TypeAlias = Literal["text", "image", tkinter._Compound]
class Style:
master: Any
master: Incomplete
tk: _tkinter.TkappType
def __init__(self, master: tkinter.Misc | None = ...) -> None: ...
def configure(self, style, query_opt: Any | None = ..., **kw): ...
def map(self, style, query_opt: Any | None = ..., **kw): ...
def lookup(self, style, option, state: Any | None = ..., default: Any | None = ...): ...
def layout(self, style, layoutspec: Any | None = ...): ...
def configure(self, style, query_opt: Incomplete | None = ..., **kw): ...
def map(self, style, query_opt: Incomplete | None = ..., **kw): ...
def lookup(self, style, option, state: Incomplete | None = ..., default: Incomplete | None = ...): ...
def layout(self, style, layoutspec: Incomplete | None = ...): ...
def element_create(self, elementname, etype, *args, **kw) -> None: ...
def element_names(self): ...
def element_options(self, elementname): ...
def theme_create(self, themename, parent: Any | None = ..., settings: Any | None = ...) -> None: ...
def theme_create(self, themename, parent: Incomplete | None = ..., settings: Incomplete | None = ...) -> None: ...
def theme_settings(self, themename, settings) -> None: ...
def theme_names(self) -> tuple[str, ...]: ...
@overload
@@ -60,10 +61,10 @@ class Style:
def theme_use(self, themename: None = ...) -> str: ...
class Widget(tkinter.Widget):
def __init__(self, master: tkinter.Misc | None, widgetname, kw: Any | None = ...) -> None: ...
def __init__(self, master: tkinter.Misc | None, widgetname, kw: Incomplete | None = ...) -> None: ...
def identify(self, x: int, y: int) -> str: ...
def instate(self, statespec, callback: Any | None = ..., *args, **kw): ...
def state(self, statespec: Any | None = ...): ...
def instate(self, statespec, callback: Incomplete | None = ..., *args, **kw): ...
def state(self, statespec: Incomplete | None = ...): ...
class Button(Widget):
def __init__(
@@ -77,7 +78,7 @@ class Button(Widget):
default: Literal["normal", "active", "disabled"] = ...,
image: tkinter._ImageSpec = ...,
name: str = ...,
padding: Any = ..., # undocumented
padding: Incomplete = ..., # undocumented
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -96,7 +97,7 @@ class Button(Widget):
cursor: tkinter._Cursor = ...,
default: Literal["normal", "active", "disabled"] = ...,
image: tkinter._ImageSpec = ...,
padding: Any = ...,
padding: Incomplete = ...,
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -123,7 +124,7 @@ class Checkbutton(Widget):
name: str = ...,
offvalue: Any = ...,
onvalue: Any = ...,
padding: Any = ..., # undocumented
padding: Incomplete = ..., # undocumented
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -147,7 +148,7 @@ class Checkbutton(Widget):
image: tkinter._ImageSpec = ...,
offvalue: Any = ...,
onvalue: Any = ...,
padding: Any = ...,
padding: Incomplete = ...,
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -255,8 +256,8 @@ class Combobox(Entry):
invalidcommand: tkinter._EntryValidateCommand = ..., # undocumented
justify: Literal["left", "center", "right"] = ...,
name: str = ...,
postcommand: Callable[[], Any] | str = ...,
show: Any = ..., # undocumented
postcommand: Callable[[], object] | str = ...,
show: Incomplete = ..., # undocumented
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -280,8 +281,8 @@ class Combobox(Entry):
height: int = ...,
invalidcommand: tkinter._EntryValidateCommand = ...,
justify: Literal["left", "center", "right"] = ...,
postcommand: Callable[[], Any] | str = ...,
show: Any = ...,
postcommand: Callable[[], object] | str = ...,
show: Incomplete = ...,
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -308,8 +309,8 @@ class Combobox(Entry):
height: int = ...,
invalidcommand: tkinter._EntryValidateCommand = ...,
justify: Literal["left", "center", "right"] = ...,
postcommand: Callable[[], Any] | str = ...,
show: Any = ...,
postcommand: Callable[[], object] | str = ...,
show: Incomplete = ...,
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -477,7 +478,7 @@ class Menubutton(Widget):
image: tkinter._ImageSpec = ...,
menu: tkinter.Menu = ...,
name: str = ...,
padding: Any = ..., # undocumented
padding: Incomplete = ..., # undocumented
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -496,7 +497,7 @@ class Menubutton(Widget):
direction: Literal["above", "below", "left", "right", "flush"] = ...,
image: tkinter._ImageSpec = ...,
menu: tkinter.Menu = ...,
padding: Any = ...,
padding: Incomplete = ...,
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -546,7 +547,7 @@ class Notebook(Widget):
sticky: str = ..., # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty
padding: tkinter._Padding = ...,
text: str = ...,
image: Any = ..., # Sequence of an image name, followed by zero or more (sequences of one or more state names followed by an image name)
image: Incomplete = ..., # Sequence of an image name, followed by zero or more (sequences of one or more state names followed by an image name)
compound: tkinter._Compound = ...,
underline: int = ...,
) -> None: ...
@@ -555,8 +556,8 @@ class Notebook(Widget):
def identify(self, x: int, y: int) -> str: ...
def index(self, tab_id): ...
def insert(self, pos, child, **kw) -> None: ...
def select(self, tab_id: Any | None = ...): ...
def tab(self, tab_id, option: Any | None = ..., **kw): ...
def select(self, tab_id: Incomplete | None = ...): ...
def tab(self, tab_id, option: Incomplete | None = ..., **kw): ...
def tabs(self): ...
def enable_traversal(self) -> None: ...
@@ -603,10 +604,10 @@ class Panedwindow(Widget, tkinter.PanedWindow):
) -> dict[str, tuple[str, str, str, Any, Any]] | None: ...
@overload
def config(self, cnf: str) -> tuple[str, str, str, Any, Any]: ...
forget: Any
forget: Incomplete
def insert(self, pos, child, **kw) -> None: ...
def pane(self, pane, option: Any | None = ..., **kw): ...
def sashpos(self, index, newpos: Any | None = ...): ...
def pane(self, pane, option: Incomplete | None = ..., **kw): ...
def sashpos(self, index, newpos: Incomplete | None = ...): ...
PanedWindow = Panedwindow
@@ -662,7 +663,7 @@ class Radiobutton(Widget):
cursor: tkinter._Cursor = ...,
image: tkinter._ImageSpec = ...,
name: str = ...,
padding: Any = ..., # undocumented
padding: Incomplete = ..., # undocumented
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -682,7 +683,7 @@ class Radiobutton(Widget):
compound: _TtkCompound = ...,
cursor: tkinter._Cursor = ...,
image: tkinter._ImageSpec = ...,
padding: Any = ...,
padding: Incomplete = ...,
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -705,7 +706,7 @@ class Scale(Widget, tkinter.Scale): # type: ignore[misc]
master: tkinter.Misc | None = ...,
*,
class_: str = ...,
command: str | Callable[[str], Any] = ...,
command: str | Callable[[str], object] = ...,
cursor: tkinter._Cursor = ...,
from_: float = ...,
length: tkinter._ScreenUnits = ...,
@@ -723,7 +724,7 @@ class Scale(Widget, tkinter.Scale): # type: ignore[misc]
self,
cnf: dict[str, Any] | None = ...,
*,
command: str | Callable[[str], Any] = ...,
command: str | Callable[[str], object] = ...,
cursor: tkinter._Cursor = ...,
from_: float = ...,
length: tkinter._ScreenUnits = ...,
@@ -743,7 +744,7 @@ class Scale(Widget, tkinter.Scale): # type: ignore[misc]
self,
cnf: dict[str, Any] | None = ...,
*,
command: str | Callable[[str], Any] = ...,
command: str | Callable[[str], object] = ...,
cursor: tkinter._Cursor = ...,
from_: float = ...,
length: tkinter._ScreenUnits = ...,
@@ -858,7 +859,7 @@ class Spinbox(Entry):
*,
background: tkinter._Color = ..., # undocumented
class_: str = ...,
command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ...,
command: Callable[[], object] | str | list[str] | tuple[str, ...] = ...,
cursor: tkinter._Cursor = ...,
exportselection: bool = ..., # undocumented
font: _FontDescription = ..., # undocumented
@@ -869,7 +870,7 @@ class Spinbox(Entry):
invalidcommand: tkinter._EntryValidateCommand = ..., # undocumented
justify: Literal["left", "center", "right"] = ..., # undocumented
name: str = ...,
show: Any = ..., # undocumented
show: Incomplete = ..., # undocumented
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -888,7 +889,7 @@ class Spinbox(Entry):
cnf: dict[str, Any] | None = ...,
*,
background: tkinter._Color = ...,
command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ...,
command: Callable[[], object] | str | list[str] | tuple[str, ...] = ...,
cursor: tkinter._Cursor = ...,
exportselection: bool = ...,
font: _FontDescription = ...,
@@ -898,7 +899,7 @@ class Spinbox(Entry):
increment: float = ...,
invalidcommand: tkinter._EntryValidateCommand = ...,
justify: Literal["left", "center", "right"] = ...,
show: Any = ...,
show: Incomplete = ...,
state: str = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
@@ -1042,7 +1043,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
text: str = ...,
image: tkinter._ImageSpec = ...,
anchor: tkinter._Anchor = ...,
command: str | Callable[[], Any] = ...,
command: str | Callable[[], object] = ...,
) -> None: ...
def identify(self, component, x, y): ... # Internal Method. Leave untyped
def identify_row(self, y: int) -> str: ...
@@ -1098,7 +1099,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
if sys.version_info >= (3, 8):
def selection(self) -> tuple[str, ...]: ...
else:
def selection(self, selop: Any | None = ..., items: Any | None = ...) -> tuple[str, ...]: ...
def selection(self, selop: Incomplete | None = ..., items: Incomplete | None = ...) -> tuple[str, ...]: ...
def selection_set(self, items: str | list[str] | tuple[str, ...]) -> None: ...
def selection_add(self, items: str | list[str] | tuple[str, ...]) -> None: ...
@@ -1114,7 +1115,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
# Also, it's 'callback' instead of 'func' here.
@overload
def tag_bind(
self, tagname: str, sequence: str | None = ..., callback: Callable[[tkinter.Event[Treeview]], Any] | None = ...
self, tagname: str, sequence: str | None = ..., callback: Callable[[tkinter.Event[Treeview]], object] | None = ...
) -> str: ...
@overload
def tag_bind(self, tagname: str, sequence: str | None, callback: str) -> None: ...
@@ -1144,8 +1145,8 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
def tag_has(self, tagname: str, item: str) -> bool: ...
class LabeledScale(Frame):
label: Any
scale: Any
label: Incomplete
scale: Incomplete
# TODO: don't any-type **kw. That goes to Frame.__init__.
def __init__(
self,
@@ -1155,7 +1156,7 @@ class LabeledScale(Frame):
to: float = ...,
*,
compound: Literal["top", "bottom"] = ...,
**kw: Any,
**kw,
) -> None: ...
# destroy is overridden, signature does not change
value: Any
@@ -1170,8 +1171,8 @@ class OptionMenu(Menubutton):
# rest of these are keyword-only because *args syntax used above
style: str = ...,
direction: Literal["above", "below", "left", "right", "flush"] = ...,
command: Callable[[tkinter.StringVar], Any] | None = ...,
command: Callable[[tkinter.StringVar], object] | None = ...,
) -> None: ...
# configure, config, cget, destroy are inherited from Menubutton
# destroy and __setitem__ are overridden, signature does not change
def set_menu(self, default: Any | None = ..., *values) -> None: ...
def set_menu(self, default: Incomplete | None = ..., *values) -> None: ...