From aed20207ac51389699fd3f1aaf9ee78865ad47ac Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 26 Aug 2020 13:40:01 +0300 Subject: [PATCH 1/2] wrap it in Optional --- stdlib/3/tkinter/__init__.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/3/tkinter/__init__.pyi b/stdlib/3/tkinter/__init__.pyi index f7b5c71b3a45..38f060822da1 100644 --- a/stdlib/3/tkinter/__init__.pyi +++ b/stdlib/3/tkinter/__init__.pyi @@ -581,7 +581,8 @@ class Tk(Misc, Wm): def loadtk(self) -> None: ... # differs from _tkinter.TkappType.loadtk def destroy(self) -> None: ... def readprofile(self, baseName: str, className: str) -> None: ... - report_callback_exception: Callable[[Type[BaseException], BaseException, TracebackType], Any] + # This really shouldn't be Optional. It's a hack to make assigning to Tk().report_callback_exception work. + report_callback_exception: Optional[Callable[[Type[BaseException], BaseException, TracebackType], Any]] # 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] From 4efeacca54d87ba9c765d4750d0b2f7513067b89 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 26 Aug 2020 14:07:13 +0300 Subject: [PATCH 2/2] use callback protocol instead of stupid hack --- stdlib/3/tkinter/__init__.pyi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stdlib/3/tkinter/__init__.pyi b/stdlib/3/tkinter/__init__.pyi index 38f060822da1..7646f9c12224 100644 --- a/stdlib/3/tkinter/__init__.pyi +++ b/stdlib/3/tkinter/__init__.pyi @@ -4,7 +4,7 @@ from enum import Enum from tkinter.constants import * # comment this out to find undefined identifier names with flake8 from tkinter.font import _FontDescription from types import TracebackType -from typing import Any, Callable, Dict, Generic, List, Optional, Tuple, Type, TypeVar, Union, overload +from typing import Any, Callable, Dict, Generic, List, Optional, Protocol, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal, TypedDict # Using anything from tkinter.font in this file means that 'import tkinter' @@ -540,6 +540,9 @@ _TkOptionName = Literal[ "width", ] +class _ExceptionReportingCallback(Protocol): + def __call__(self, __exc: Type[BaseException], __val: BaseException, __tb: TracebackType) -> Any: ... + class Tk(Misc, Wm): master: None children: Dict[str, Any] @@ -581,8 +584,7 @@ class Tk(Misc, Wm): def loadtk(self) -> None: ... # differs from _tkinter.TkappType.loadtk def destroy(self) -> None: ... def readprofile(self, baseName: str, className: str) -> None: ... - # This really shouldn't be Optional. It's a hack to make assigning to Tk().report_callback_exception work. - report_callback_exception: Optional[Callable[[Type[BaseException], BaseException, TracebackType], Any]] + 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]