Skip to content

Commit

Permalink
Update typing settings & dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 committed Jan 17, 2025
1 parent 100397b commit ce475e2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
19 changes: 6 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/idlemypyextension/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 15 additions & 12 deletions src/idlemypyextension/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
__author__ = "CoolCat467"
__license__ = "GNU General Public License Version 3"

import contextlib
import json
import math
import os
Expand All @@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand All @@ -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)
4 changes: 3 additions & 1 deletion src/idlemypyextension/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit ce475e2

Please sign in to comment.