Add types to some untyped tkinter.Canvas methods (#5868)

* coords
* gettags
* itemconfigure, itemconfig
* tag_raise, tag_lower, their aliases
* dtag

Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
This commit is contained in:
Akuli
2021-08-07 17:01:56 +03:00
committed by GitHub
parent 9301131976
commit 1cd719ba8d

View File

@@ -105,7 +105,7 @@ _TkinterSequence2D = Union[List[List[_T]], List[Tuple[_T, ...]], Tuple[List[_T],
_Anchor = Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] # manual page: Tk_GetAnchor
_Bitmap = str # manual page: Tk_GetBitmap
_ButtonCommand = Union[str, Callable[[], Any]] # return value is returned from Button.invoke()
_CanvasItemId = int # handles for items created on a canvas - can be passed to Canvas.delete()
_CanvasItemId = int
_Color = str # typically '#rrggbb', '#rgb' or color names.
_Compound = Literal["top", "left", "center", "right", "bottom", "none"] # -compound in manual page named 'options'
_Cursor = Union[str, Tuple[str], Tuple[str, str], Tuple[str, str, str], Tuple[str, str, str, str]] # manual page: Tk_GetCursor
@@ -1104,7 +1104,12 @@ class Canvas(Widget, XView, YView):
def tag_unbind(self, tagOrId: Union[str, int], sequence: str, funcid: Optional[str] = ...) -> None: ...
def canvasx(self, screenx, gridspacing: Optional[Any] = ...): ...
def canvasy(self, screeny, gridspacing: Optional[Any] = ...): ...
def coords(self, *args): ...
@overload
def coords(self) -> list[float]: ...
@overload
def coords(self, __args: _TkinterSequence[int] | _TkinterSequence[float]) -> None: ...
@overload
def coords(self, __x1: float, __y1: float, *args: float) -> None: ...
def create_arc(self, *args, **kw) -> _CanvasItemId: ...
def create_bitmap(self, *args, **kw) -> _CanvasItemId: ...
def create_image(self, *args, **kw) -> _CanvasItemId: ...
@@ -1268,7 +1273,10 @@ class Canvas(Widget, XView, YView):
) -> _CanvasItemId: ...
def dchars(self, *args): ...
def delete(self, *tagsOrCanvasIds: Union[str, _CanvasItemId]) -> None: ...
def dtag(self, *args): ...
@overload
def dtag(self, __tag: str, __tag_to_delete: str | None = ...) -> None: ...
@overload
def dtag(self, __id: _CanvasItemId, __tag_to_delete: str) -> None: ...
def find(self, *args): ...
def find_above(self, tagOrId: Union[str, _CanvasItemId]): ...
def find_all(self): ...
@@ -1278,23 +1286,32 @@ class Canvas(Widget, XView, YView):
def find_overlapping(self, x1, y1, x2, y2): ...
def find_withtag(self, tagOrId: Union[str, _CanvasItemId]): ...
def focus(self, *args): ...
def gettags(self, *args): ...
def gettags(self, __tagOrId: str | _CanvasItemId) -> Tuple[str, ...]: ...
def icursor(self, *args): ...
def index(self, *args): ...
def insert(self, *args): ...
def itemcget(self, tagOrId, option): ...
def itemconfigure(self, tagOrId, cnf: Optional[Any] = ..., **kw): ...
itemconfig: Any
def tag_lower(self, *args): ...
lower: Any
# itemconfigure kwargs depend on item type, which is not known when type checking
def itemconfigure(
self, tagOrId: str | _CanvasItemId, cnf: dict[str, Any] | None = ..., **kw: Any
) -> dict[str, tuple[str, str, str, str, str]] | None: ...
itemconfig = itemconfigure
def move(self, *args): ...
if sys.version_info >= (3, 8):
def moveto(
self, tagOrId: Union[str, _CanvasItemId], x: Union[Literal[""], float] = ..., y: Union[Literal[""], float] = ...
) -> None: ...
def postscript(self, cnf=..., **kw): ...
def tag_raise(self, *args): ...
lift: Any
# tkinter does:
# lower = tag_lower
# lift = tkraise = tag_raise
#
# But mypy doesn't like aliasing here (maybe because Misc defines the same names)
def tag_lower(self, __first: str | _CanvasItemId, __second: str | _CanvasItemId | None = ...) -> None: ...
def lower(self, __first: str | _CanvasItemId, __second: str | _CanvasItemId | None = ...) -> None: ... # type: ignore
def tag_raise(self, __first: str | _CanvasItemId, __second: str | _CanvasItemId | None = ...) -> None: ...
def tkraise(self, __first: str | _CanvasItemId, __second: str | _CanvasItemId | None = ...) -> None: ... # type: ignore
def lift(self, __first: str | _CanvasItemId, __second: str | _CanvasItemId | None = ...) -> None: ... # type: ignore
def scale(self, *args): ...
def scan_mark(self, x, y): ...
def scan_dragto(self, x, y, gain: int = ...): ...