[tkinter] Annotate few methods (#15273)

This commit is contained in:
Semyon Moroz
2026-01-15 23:28:12 +00:00
committed by GitHub
parent 5e477a316c
commit ee1e94d430
2 changed files with 53 additions and 34 deletions
+29 -19
View File
@@ -1,6 +1,7 @@
import sys
from _typeshed import FileDescriptorLike, Incomplete
from collections.abc import Callable
from typing import Any, ClassVar, Final, final
from typing import Any, ClassVar, Final, Literal, final, overload
from typing_extensions import TypeAlias, deprecated
# _tkinter is meant to be only used internally by tkinter, but some tkinter
@@ -54,22 +55,23 @@ _TkinterTraceFunc: TypeAlias = Callable[[tuple[str, ...]], object]
@final
class TkappType:
# Please keep in sync with tkinter.Tk
def adderrorinfo(self, msg: str, /): ...
def adderrorinfo(self, msg: str, /) -> None: ...
def call(self, command: Any, /, *args: Any) -> Any: ...
def createcommand(self, name: str, func, /): ...
# TODO: Figure out what arguments the following `func` callbacks should accept
def createcommand(self, name: str, func: Callable[..., object], /) -> None: ...
if sys.platform != "win32":
def createfilehandler(self, file, mask: int, func, /): ...
def deletefilehandler(self, file, /) -> None: ...
def createfilehandler(self, file: FileDescriptorLike, mask: int, func: Callable[..., object], /) -> None: ...
def deletefilehandler(self, file: FileDescriptorLike, /) -> None: ...
def createtimerhandler(self, milliseconds: int, func, /): ...
def deletecommand(self, name: str, /): ...
def dooneevent(self, flags: int = 0, /): ...
def createtimerhandler(self, milliseconds: int, func: Callable[..., object], /): ...
def deletecommand(self, name: str, /) -> None: ...
def dooneevent(self, flags: int = 0, /) -> int: ...
def eval(self, script: str, /) -> str: ...
def evalfile(self, fileName: str, /): ...
def exprboolean(self, s: str, /): ...
def exprdouble(self, s: str, /): ...
def exprlong(self, s: str, /): ...
def exprstring(self, s: str, /): ...
def evalfile(self, fileName: str, /) -> str: ...
def exprboolean(self, s: str, /) -> Literal[0, 1]: ...
def exprdouble(self, s: str, /) -> float: ...
def exprlong(self, s: str, /) -> int: ...
def exprstring(self, s: str, /) -> str: ...
def getboolean(self, arg, /) -> bool: ...
def getdouble(self, arg, /) -> float: ...
def getint(self, arg, /) -> int: ...
@@ -81,15 +83,23 @@ class TkappType:
def loadtk(self) -> None: ...
def mainloop(self, threshold: int = 0, /) -> None: ...
def quit(self) -> None: ...
def record(self, script: str, /): ...
def record(self, script: str, /) -> str: ...
def setvar(self, *ags, **kwargs): ...
if sys.version_info < (3, 11):
@deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.")
def split(self, arg, /): ...
def splitlist(self, arg, /): ...
def splitlist(self, arg, /) -> tuple[Incomplete, ...]: ...
def unsetvar(self, *args, **kwargs): ...
def wantobjects(self, *args, **kwargs): ...
if sys.version_info >= (3, 14):
@overload
def wantobjects(self) -> Literal[0, 1]: ...
else:
@overload
def wantobjects(self) -> bool: ...
@overload
def wantobjects(self, wantobjects: Literal[0, 1] | bool, /) -> None: ...
def willdispatch(self) -> None: ...
if sys.version_info >= (3, 12):
def gettrace(self, /) -> _TkinterTraceFunc | None: ...
@@ -112,7 +122,7 @@ TK_VERSION: Final[str]
@final
class TkttType:
def deletetimerhandler(self): ...
def deletetimerhandler(self) -> None: ...
if sys.version_info >= (3, 13):
def create(
@@ -125,7 +135,7 @@ if sys.version_info >= (3, 13):
sync: bool = False,
use: str | None = None,
/,
): ...
) -> TkappType: ...
else:
def create(
@@ -138,7 +148,7 @@ else:
sync: bool = False,
use: str | None = None,
/,
): ...
) -> TkappType: ...
def getbusywaitinterval() -> int: ...
def setbusywaitinterval(new_val: int, /) -> None: ...