From 877b241301c9ebca0350c11856b7107171308976 Mon Sep 17 00:00:00 2001 From: Jesse205 <2055675594@qq.com> Date: Wed, 27 May 2026 22:30:42 +0800 Subject: [PATCH 1/6] Correct report_callback_exception type from attribute to method --- stdlib/tkinter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 9f1c346cdc19..897af865fbca 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -1063,7 +1063,7 @@ class Tk(Misc, Wm): config = configure def destroy(self) -> None: ... def readprofile(self, baseName: str, className: str) -> None: ... - report_callback_exception: Callable[[type[BaseException], BaseException, TracebackType | None], object] + def report_callback_exception(self, exc: type[BaseException], val: BaseException, tb:TracebackType | None) -> object: ... # Tk has __getattr__ so that tk_instance.foo falls back to tk_instance.tk.foo # Please keep in sync with _tkinter.TkappType. # Some methods are intentionally missing because they are inherited from Misc instead. From 5c891dbb7363ce4f34531378dec3d6beba275c73 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 May 2026 14:37:33 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tkinter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 897af865fbca..f1cd4c6a707e 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -1063,7 +1063,7 @@ class Tk(Misc, Wm): config = configure def destroy(self) -> None: ... def readprofile(self, baseName: str, className: str) -> None: ... - def report_callback_exception(self, exc: type[BaseException], val: BaseException, tb:TracebackType | None) -> object: ... + def report_callback_exception(self, exc: type[BaseException], val: BaseException, tb: TracebackType | None) -> object: ... # Tk has __getattr__ so that tk_instance.foo falls back to tk_instance.tk.foo # Please keep in sync with _tkinter.TkappType. # Some methods are intentionally missing because they are inherited from Misc instead. From 1d64e2bae58bebadc5c68d14ffbdd51ac48028f6 Mon Sep 17 00:00:00 2001 From: Jesse205 <2055675594@qq.com> Date: Thu, 28 May 2026 00:09:51 +0800 Subject: [PATCH 3/6] Add and fix tests --- stdlib/@tests/test_cases/check_tkinter.py | 10 ++++++++-- stdlib/tkinter/__init__.pyi | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/stdlib/@tests/test_cases/check_tkinter.py b/stdlib/@tests/test_cases/check_tkinter.py index eb344f3a234a..38aa84545014 100644 --- a/stdlib/@tests/test_cases/check_tkinter.py +++ b/stdlib/@tests/test_cases/check_tkinter.py @@ -13,8 +13,14 @@ def custom_handler(exc: type[BaseException], val: BaseException, tb: types.Trace root = tkinter.Tk() -root.report_callback_exception = traceback.print_exception -root.report_callback_exception = custom_handler +root.report_callback_exception = traceback.print_exception # type: ignore[method-assign] +root.report_callback_exception = custom_handler # type: ignore[method-assign] +root.report_callback_exception(TypeError, TypeError("no"), None) + + +class App(tkinter.Tk): + def report_callback_exception(self, exc: type[BaseException], val: BaseException, tb: types.TracebackType | None) -> None: + print("oh no") def foo(x: int, y: str) -> None: diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index f1cd4c6a707e..ed55cf6de2b1 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -1063,7 +1063,8 @@ class Tk(Misc, Wm): config = configure def destroy(self) -> None: ... def readprofile(self, baseName: str, className: str) -> None: ... - def report_callback_exception(self, exc: type[BaseException], val: BaseException, tb: TracebackType | None) -> object: ... + def report_callback_exception(self, exc: type[BaseException], val: BaseException, tb: TracebackType | None, /) -> object: ... + # Tk has __getattr__ so that tk_instance.foo falls back to tk_instance.tk.foo # Please keep in sync with _tkinter.TkappType. # Some methods are intentionally missing because they are inherited from Misc instead. From b4161dcddf31ec2104ea08a12594915a41073353 Mon Sep 17 00:00:00 2001 From: Jesse205 <2055675594@qq.com> Date: Thu, 28 May 2026 01:42:48 +0800 Subject: [PATCH 4/6] Fix tests again --- stdlib/@tests/test_cases/check_tkinter.py | 7 ------- .../test_cases/check_tkinter_method_assign.py | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 stdlib/@tests/test_cases/check_tkinter_method_assign.py diff --git a/stdlib/@tests/test_cases/check_tkinter.py b/stdlib/@tests/test_cases/check_tkinter.py index 38aa84545014..276b1f925762 100644 --- a/stdlib/@tests/test_cases/check_tkinter.py +++ b/stdlib/@tests/test_cases/check_tkinter.py @@ -2,19 +2,12 @@ import sys import tkinter -import traceback import types from typing import Optional, Tuple from typing_extensions import assert_type -def custom_handler(exc: type[BaseException], val: BaseException, tb: types.TracebackType | None) -> None: - print("oh no") - - root = tkinter.Tk() -root.report_callback_exception = traceback.print_exception # type: ignore[method-assign] -root.report_callback_exception = custom_handler # type: ignore[method-assign] root.report_callback_exception(TypeError, TypeError("no"), None) diff --git a/stdlib/@tests/test_cases/check_tkinter_method_assign.py b/stdlib/@tests/test_cases/check_tkinter_method_assign.py new file mode 100644 index 000000000000..5fbd2a2d6c7b --- /dev/null +++ b/stdlib/@tests/test_cases/check_tkinter_method_assign.py @@ -0,0 +1,20 @@ +# mypy: disable-error-code="method-assign" +from __future__ import annotations + +import tkinter +import traceback +import types + + +def custom_handler(exc: type[BaseException], val: BaseException, tb: types.TracebackType | None) -> None: + print("oh no") + + +def custom_wrong_handler(exc: BaseException, val: BaseException, tb: types.TracebackType | None) -> None: + print("oh no") + + +root = tkinter.Tk() +root.report_callback_exception = traceback.print_exception +root.report_callback_exception = custom_handler +root.report_callback_exception = custom_wrong_handler # type: ignore From 28e88906cfe1976a28a48049102f746ba6296736 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 May 2026 17:44:52 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/@tests/test_cases/check_tkinter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/@tests/test_cases/check_tkinter.py b/stdlib/@tests/test_cases/check_tkinter.py index 276b1f925762..974837448621 100644 --- a/stdlib/@tests/test_cases/check_tkinter.py +++ b/stdlib/@tests/test_cases/check_tkinter.py @@ -6,7 +6,6 @@ from typing import Optional, Tuple from typing_extensions import assert_type - root = tkinter.Tk() root.report_callback_exception(TypeError, TypeError("no"), None) From f70829973a05a24c4cd20276187b346ac3b7c17b Mon Sep 17 00:00:00 2001 From: Jesse205 <2055675594@qq.com> Date: Thu, 28 May 2026 02:05:21 +0800 Subject: [PATCH 6/6] Use Tk.report_callback_exception directly --- stdlib/@tests/test_cases/check_tkinter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/@tests/test_cases/check_tkinter.py b/stdlib/@tests/test_cases/check_tkinter.py index 276b1f925762..44e1823c74e6 100644 --- a/stdlib/@tests/test_cases/check_tkinter.py +++ b/stdlib/@tests/test_cases/check_tkinter.py @@ -8,7 +8,7 @@ root = tkinter.Tk() -root.report_callback_exception(TypeError, TypeError("no"), None) +tkinter.Tk.report_callback_exception(root, TypeError, TypeError("no"), None) class App(tkinter.Tk):