From ce475e2b2cc6c3f370e84de4c125613d1335d526 Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Fri, 17 Jan 2025 00:10:42 -0600 Subject: [PATCH] Update typing settings & dependencies --- pyproject.toml | 19 ++++++------------- src/idlemypyextension/client.py | 2 +- src/idlemypyextension/extension.py | 27 +++++++++++++++------------ src/idlemypyextension/utils.py | 4 +++- test-requirements.txt | 4 ++-- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 30c0a0d..5ecc418 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development", "Topic :: Text Editors :: Integrated Development Environments (IDE)", @@ -56,24 +57,16 @@ idlemypyextension = ["py.typed"] [tool.mypy] files = ["src/idlemypyextension/",] mypy_path = "stubs" -check_untyped_defs = true -disallow_any_generics = true -disallow_untyped_calls = true -disallow_untyped_defs = true -ignore_missing_imports = true -no_implicit_optional = true -no_implicit_reexport = true show_column_numbers = true show_error_codes = true show_traceback = true +disallow_any_decorated = true +disallow_any_unimported = true +ignore_missing_imports = true +local_partial_types = true +no_implicit_optional = true strict = true -#strict_bytes = true # Enable in after next mypy release -strict_equality = true -warn_redundant_casts = true -warn_return_any = true warn_unreachable = true -warn_unused_configs = true -warn_unused_ignores = true [tool.ruff.lint.isort] combine-as-imports = true diff --git a/src/idlemypyextension/client.py b/src/idlemypyextension/client.py index 401c32f..6fb6e97 100644 --- a/src/idlemypyextension/client.py +++ b/src/idlemypyextension/client.py @@ -306,7 +306,7 @@ async def request( async with REQUEST_LOCK: if sys.platform == "win32" or FORCE_BASE_REQUEST: return await _request_win32(name, request_arguments, timeout) - # Windows run thinks unreachable, everything else knows it is + # Windows run thinks unreachable, everything else knows it is not return await _request_linux( # type: ignore[unreachable,unused-ignore] name, request_arguments, diff --git a/src/idlemypyextension/extension.py b/src/idlemypyextension/extension.py index 095e744..b1b9451 100644 --- a/src/idlemypyextension/extension.py +++ b/src/idlemypyextension/extension.py @@ -24,6 +24,7 @@ __author__ = "CoolCat467" __license__ = "GNU General Public License Version 3" +import contextlib import json import math import os @@ -32,14 +33,14 @@ import traceback from functools import partial, wraps from idlelib.config import idleConf -from typing import TYPE_CHECKING, Any, ClassVar, Final +from typing import TYPE_CHECKING, ClassVar, Final from idlemypyextension import annotate, client, mttkinter, tktrio, utils if TYPE_CHECKING: from collections.abc import Callable from idlelib.pyshell import PyShellEditorWindow - from tkinter import Event + from tkinter import Event, Misc DAEMON_TIMEOUT_MIN: Final = 5 ACTION_TIMEOUT_MIN: Final = 5 @@ -193,13 +194,14 @@ def __init__(self, editwin: PyShellEditorWindow) -> None: def get_async( self, name: str, - ) -> Callable[[Event[Any]], str]: + ) -> Callable[[Event[Misc]], str]: """Get sync callable to run async function.""" async_function = getattr(self, name) + # Type of decorated function contains type `Any` @wraps(async_function) @utils.log_exceptions - def call_trio(event: Event[Any]) -> str: + def call_trio(event: Event[Misc]) -> str: # type: ignore[misc] self.triorun(partial(async_function, event)) return "break" @@ -417,7 +419,7 @@ async def ensure_daemon_running(self) -> bool: async def shutdown_dmypy_daemon_event_async( self, - event: Event[Any], + event: Event[Misc], ) -> str: """Shutdown dmypy daemon event handler.""" # pylint: disable=unused-argument @@ -651,7 +653,7 @@ def initial(self) -> tuple[str | None, str | None]: # Everything worked return None, file - async def suggest_signature_event_async(self, event: Event[Any]) -> str: + async def suggest_signature_event_async(self, event: Event[Misc]) -> str: """Handle suggest signature event.""" # pylint: disable=unused-argument init_return, file = self.initial() @@ -712,7 +714,7 @@ def type_check_add_response_comments( # as it freezes a bit while mypy looks at the file self.text.bell() - async def type_check_event_async(self, event: Event[Any]) -> str: + async def type_check_event_async(self, event: Event[Misc]) -> str: """Perform a mypy check and add comments.""" init_return, file = self.initial() @@ -738,19 +740,19 @@ async def type_check_event_async(self, event: Event[Any]) -> str: return "break" @utils.log_exceptions - def remove_type_comments_event(self, _event: Event[Any]) -> str: + def remove_type_comments_event(self, _event: Event[Misc]) -> str: """Remove selected extension comments.""" self.remove_selected_extension_comments() return "break" @utils.log_exceptions - def remove_all_type_comments(self, _event: Event[Any]) -> str: + def remove_all_type_comments(self, _event: Event[Misc]) -> str: """Remove all extension comments.""" self.remove_all_extension_comments() return "break" @utils.log_exceptions - def find_next_type_comment_event(self, _event: Event[Any]) -> str: + def find_next_type_comment_event(self, _event: Event[Misc]) -> str: """Find next extension comment by hacking the search dialog engine.""" # Reload configuration self.reload() @@ -773,9 +775,10 @@ def unregister_async_events(self) -> None: def close(self) -> None: """Extension cleanup before IDLE window closes.""" # Wrapped in try except so failure doesn't cause zombie windows. - del self.triorun + with contextlib.suppress(AttributeError): + del self.triorun try: mttkinter.restore() self.unregister_async_events() except Exception as exc: - traceback.print_exception(exc) + utils.extension_log_exception(exc) diff --git a/src/idlemypyextension/utils.py b/src/idlemypyextension/utils.py index 241aa28..338f31f 100644 --- a/src/idlemypyextension/utils.py +++ b/src/idlemypyextension/utils.py @@ -361,10 +361,12 @@ def extension_log(content: str) -> None: fp.write("\n") -def extension_log_exception(exc: BaseException) -> None: +def extension_log_exception(exc: BaseException, print_: bool = True) -> None: """Log exception to extension log.""" exception_text = "".join(traceback.format_exception(exc)) extension_log(exception_text) + if print_: + print(exception_text, file=sys.stderr) def log_exceptions(function: Callable[PS, T]) -> Callable[PS, T]: diff --git a/test-requirements.txt b/test-requirements.txt index 6f7ef3e..1ec4147 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -62,7 +62,7 @@ pytest-cov==6.0.0 # via -r test-requirements.in pytest-trio==0.8.0 # via -r test-requirements.in -ruff==0.9.1 +ruff==0.9.2 # via -r test-requirements.in sniffio==1.3.1 # via trio @@ -83,5 +83,5 @@ typing-extensions==4.12.2 # -r test-requirements.in # black # mypy -uv==0.5.18 +uv==0.5.20 # via -r test-requirements.in