Slightly improve annotation of tkinter.Tk#2498
Conversation
|
The type annotation for Issue 1In a Tk subclass, after overriding from tkinter import Tk
from types import TracebackType
from typing import override
class App(Tk):
@override
def report_callback_exception(
self,
exc_type: type[BaseException],
exc_value: BaseException,
exc_traceback: TracebackType | None,
):
pass(report-callback-exception) PS G:\programming\python\lab\report_callback_exception> pyright
g:\programming\python\lab\report_callback_exception\main.py
g:\programming\python\lab\report_callback_exception\main.py:8:9 - error: Method "report_callback_exception" overrides class "Tk" in an incompatible manner
Positional parameter count mismatch; base method has 3, but override has 4
Parameter 2 type mismatch: base parameter is type "BaseException", override parameter is type "type[BaseException]"
Parameter 3 type mismatch: base parameter is type "TracebackType | None", override parameter is type "BaseException"
Type "BaseException" is not assignable to type "type[BaseException]"
Type "TracebackType | None" is not assignable to type "BaseException"
"TracebackType" is not assignable to "BaseException" (reportIncompatibleMethodOverride)
1 error, 0 warnings, 0 informationsIssue 2Without manual assignment, but manually calling from tkinter import Tk
import sys
def main():
try:
print(0 / 0)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
assert exc_type is not None
assert exc_value is not None
Tk.report_callback_exception(exc_type, exc_value, exc_traceback)(report-callback-exception) PS G:\programming\python\lab\report_callback_exception> & g:\programming\python\lab\report_callback_exception\.venv\Scripts\python.exe g:/programming/python/lab/report_callback_exception/main.py
Traceback (most recent call last):
File "g:\programming\python\lab\report_callback_exception\main.py", line 7, in main
0 / 0
~~^~~
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "g:\programming\python\lab\report_callback_exception\main.py", line 16, in <module>
main()
~~~~^^
File "g:\programming\python\lab\report_callback_exception\main.py", line 12, in main
Tk.report_callback_exception(exc_type, exc_value, exc_traceback)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Tk.report_callback_exception() missing 1 required positional argument: 'tb'(report-callback-exception) PS G:\programming\python\lab\report_callback_exception> pyright
0 errors, 0 warnings, 0 informations
The above statement is irrelevant to this issue. mypy's error when assigning to a method is intentional, therefore #1767 is not an issue. |
Closes: #1767