Skip to content

Improve _tkinter #6908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"stdlib/distutils/command",
"stdlib/lib2to3/refactor.pyi",
"stdlib/sqlite3/dbapi2.pyi",
"stdlib/_tkinter.pyi",
"stdlib/tkinter",
"stdlib/unittest/mock.pyi",
"stdlib/xml/dom/NodeFilter.pyi",
Expand Down
91 changes: 54 additions & 37 deletions stdlib/_tkinter.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ from typing_extensions import Literal, final
# (<textindex object: '1.0'>, <textindex object: '2.0'>)
@final
class Tcl_Obj:
string: str # str(tclobj) returns this
string: str | bytes
typename: str
__hash__: None # type: ignore[assignment]
def __eq__(self, other): ...
def __ge__(self, other): ...
def __gt__(self, other): ...
def __le__(self, other): ...
def __lt__(self, other): ...
def __ne__(self, other): ...

class TclError(Exception): ...

Expand All @@ -42,39 +49,40 @@ class TclError(Exception): ...
@final
class TkappType:
# Please keep in sync with tkinter.Tk
def adderrorinfo(self, __msg): ...
def call(self, __command: Any, *args: Any) -> Any: ...
def createcommand(self, __name, __func): ...
if sys.platform != "win32":
def createfilehandler(self, __file, __mask, __func): ...
def deletefilehandler(self, __file): ...
def createtimerhandler(self, __milliseconds, __func): ...
def deletecommand(self, __name): ...
def dooneevent(self, __flags: int = ...): ...
def eval(self, __script: str) -> str: ...
adderrorinfo: Any
createcommand: Any
createfilehandler: Any
createtimerhandler: Any
deletecommand: Any
deletefilehandler: Any
dooneevent: Any
evalfile: Any
exprboolean: Any
exprdouble: Any
exprlong: Any
exprstring: Any
getboolean: Any
getdouble: Any
getint: Any
getvar: Any
globalgetvar: Any
globalsetvar: Any
globalunsetvar: Any
interpaddr: Any
loadtk: Any
mainloop: Any
quit: Any
record: Any
setvar: Any
def evalfile(self, __fileName): ...
def exprboolean(self, __s): ...
def exprdouble(self, __s): ...
def exprlong(self, __s): ...
def exprstring(self, __s): ...
def getboolean(self, __arg): ...
def getdouble(self, __arg): ...
def getint(self, __arg): ...
def getvar(self, *args, **kwargs): ...
def globalgetvar(self, *args, **kwargs): ...
def globalsetvar(self, *args, **kwargs): ...
def globalunsetvar(self, *args, **kwargs): ...
def interpaddr(self): ...
def loadtk(self) -> None: ...
def mainloop(self, __threshold: int = ...): ...
def quit(self): ...
def record(self, __script): ...
def setvar(self, *ags, **kwargs): ...
if sys.version_info < (3, 11):
split: Any
splitlist: Any
unsetvar: Any
wantobjects: Any
willdispatch: Any
def split(self, __arg): ...
def splitlist(self, __arg): ...
def unsetvar(self, *args, **kwargs): ...
def wantobjects(self, *args, **kwargs): ...
def willdispatch(self): ...

# These should be kept in sync with tkinter.tix constants, except ALL_EVENTS which doesn't match TCL_ALL_EVENTS
ALL_EVENTS: Literal[-3]
Expand All @@ -91,9 +99,18 @@ WRITABLE: Literal[4]
TCL_VERSION: str
TK_VERSION: str

# TODO: figure out what these are (with e.g. help()) and get rid of Any
TkttType: Any
_flatten: Any
create: Any
getbusywaitinterval: Any
setbusywaitinterval: Any
class TkttType:
def deletetimerhandler(self): ...

def create(
__screenName: str | None = ...,
__baseName: str | None = ...,
__className: str = ...,
__interactive: bool = ...,
__wantobjects: bool = ...,
__wantTk: bool = ...,
__sync: bool = ...,
__use: str | None = ...,
): ...
def getbusywaitinterval(): ...
def setbusywaitinterval(__new_val): ...
60 changes: 27 additions & 33 deletions stdlib/tkinter/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -610,44 +610,38 @@ class Tk(Misc, Wm):
@overload
def configure(self, cnf: str) -> tuple[str, str, str, Any, Any]: ...
config = configure
def loadtk(self) -> None: ... # differs from _tkinter.TkappType.loadtk
def destroy(self) -> None: ...
def readprofile(self, baseName: str, className: str) -> None: ...
report_callback_exception: _ExceptionReportingCallback
# Tk has __getattr__ so that tk_instance.foo falls back to tk_instance.tk.foo
# Please keep in sync with _tkinter.TkappType
call: Callable[..., Any]
def eval(self, __code: str) -> str: ...
adderrorinfo: Any
createcommand: Any
createfilehandler: Any
createtimerhandler: Any
deletecommand: Any
deletefilehandler: Any
dooneevent: Any
evalfile: Any
exprboolean: Any
exprdouble: Any
exprlong: Any
exprstring: Any
getboolean: Any
getdouble: Any
getint: Any
getvar: Any
globalgetvar: Any
globalsetvar: Any
globalunsetvar: Any
interpaddr: Any
mainloop: Any
quit: Any
record: Any
setvar: Any
# Please keep in sync with _tkinter.TkappType.
# Some methods are intentionally missing because they are inherited from Misc instead.
def adderrorinfo(self, __msg): ...
def call(self, __command: Any, *args: Any) -> Any: ...
def createcommand(self, __name, __func): ...
if sys.platform != "win32":
def createfilehandler(self, __file, __mask, __func): ...
def deletefilehandler(self, __file): ...
def createtimerhandler(self, __milliseconds, __func): ...
def dooneevent(self, __flags: int = ...): ...
def eval(self, __script: str) -> str: ...
def evalfile(self, __fileName): ...
def exprboolean(self, __s): ...
def exprdouble(self, __s): ...
def exprlong(self, __s): ...
def exprstring(self, __s): ...
def globalgetvar(self, *args, **kwargs): ...
def globalsetvar(self, *args, **kwargs): ...
def globalunsetvar(self, *args, **kwargs): ...
def interpaddr(self): ...
def loadtk(self) -> None: ...
def record(self, __script): ...
if sys.version_info < (3, 11):
split: Any
splitlist: Any
unsetvar: Any
wantobjects: Any
willdispatch: Any
def split(self, __arg): ...
def splitlist(self, __arg): ...
def unsetvar(self, *args, **kwargs): ...
def wantobjects(self, *args, **kwargs): ...
def willdispatch(self): ...

def Tcl(screenName: Any | None = ..., baseName: Any | None = ..., className: str = ..., useTk: bool = ...): ...

Expand Down
4 changes: 4 additions & 0 deletions tests/stubtest_allowlists/darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ stat.FILE_ATTRIBUTE_[A-Z_]+
(sqlite3(.dbapi2)?.Connection.enable_load_extension)?
(sqlite3(.dbapi2)?.Connection.load_extension)?

# Methods that come from __getattr__() at runtime
tkinter.Tk.createfilehandler
tkinter.Tk.deletefilehandler

# Exists at runtime, but missing from stubs
distutils.msvccompiler.MSVCCompiler.get_msvc_paths
distutils.msvccompiler.MSVCCompiler.set_path_env_var
Expand Down
4 changes: 4 additions & 0 deletions tests/stubtest_allowlists/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ stat.FILE_ATTRIBUTE_[A-Z_]+
(sqlite3(.dbapi2)?.Connection.enable_load_extension)?
(sqlite3(.dbapi2)?.Connection.load_extension)?

# Methods that come from __getattr__() at runtime
tkinter.Tk.createfilehandler
tkinter.Tk.deletefilehandler

# Exists at runtime, but missing from stubs
distutils.msvccompiler.MSVCCompiler.get_msvc_paths
distutils.msvccompiler.MSVCCompiler.set_path_env_var
Expand Down
22 changes: 22 additions & 0 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,28 @@ tkinter.Place.forget
tkinter.Place.place_slaves
tkinter.Place.slaves

# Methods that come from __getattr__() at runtime
tkinter.Tk.adderrorinfo
tkinter.Tk.call
tkinter.Tk.createcommand
tkinter.Tk.createtimerhandler
tkinter.Tk.dooneevent
tkinter.Tk.evalfile
tkinter.Tk.exprboolean
tkinter.Tk.exprdouble
tkinter.Tk.exprlong
tkinter.Tk.exprstring
tkinter.Tk.globalgetvar
tkinter.Tk.globalsetvar
tkinter.Tk.globalunsetvar
tkinter.Tk.interpaddr
tkinter.Tk.record
tkinter.Tk.split
tkinter.Tk.splitlist
tkinter.Tk.unsetvar
tkinter.Tk.wantobjects
tkinter.Tk.willdispatch

# Undocumented and have a comment in the source code saying "State variables (don't mess with these)"
wsgiref.handlers.BaseHandler.bytes_sent
wsgiref.handlers.BaseHandler.headers
Expand Down