Skip to content

Commit 1fe8f81

Browse files
committed
Update pre-commit and handle reloading extension
1 parent d8711af commit 1fe8f81

File tree

8 files changed

+40
-22
lines changed

8 files changed

+40
-22
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ repos:
2828
types: [file]
2929
types_or: [python, pyi]
3030
- repo: https://github.com/psf/black-pre-commit-mirror
31-
rev: 24.4.2
31+
rev: 24.8.0
3232
hooks:
3333
- id: black
3434
- repo: https://github.com/astral-sh/ruff-pre-commit
35-
rev: v0.5.5
35+
rev: v0.6.1
3636
hooks:
3737
- id: ruff
3838
types: [file]

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ select = [
105105
"FLY", # flynt
106106
"FURB", # refurb
107107
"I", # isort
108+
"ICN", # flake8-import-conventions
108109
"N", # pep8-naming
109110
"PIE", # flake8-pie
110111
"PT", # flake8-pytest-style
111112
"PYI", # flake8-pyi
112113
"Q", # flake8-quotes
114+
"R", # Refactor
113115
"RET", # flake8-return
114116
"RUF", # Ruff-specific rules
115117
"S", # flake8-bandit

src/idlemypyextension/client.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _read_request_response_json(request_response: str | bytes) -> Response:
173173
async def _request_win32(
174174
name: str,
175175
request_arguments: str,
176-
timeout: int | None = None, # noqa: TRIO109
176+
timeout: int | None = None, # noqa: ASYNC109
177177
) -> Response:
178178
"""Request from daemon on windows."""
179179

@@ -211,7 +211,7 @@ async def _receive(
211211
async def _request_linux(
212212
filename: str,
213213
request_arguments: str,
214-
timeout: float | None = None, # noqa: TRIO109
214+
timeout: float | None = None, # noqa: ASYNC109
215215
) -> Response:
216216
def find_frame_in_buffer(
217217
buffer: bytearray,
@@ -271,7 +271,7 @@ async def request(
271271
status_file: str,
272272
command: str,
273273
*,
274-
timeout: int | None = None, # noqa: TRIO109
274+
timeout: int | None = None, # noqa: ASYNC109
275275
**kwds: object,
276276
) -> Response:
277277
"""Send a request to the daemon.
@@ -317,7 +317,7 @@ async def stop(status_file: str) -> Response:
317317

318318
async def _wait_for_server(
319319
status_file: str,
320-
timeout: float = 5.0, # noqa: TRIO109
320+
timeout: float = 5.0, # noqa: ASYNC109
321321
) -> bool:
322322
"""Wait until the server is up. Return False if timed out."""
323323
try:
@@ -417,7 +417,7 @@ async def start(
417417
async def status(
418418
status_file: str,
419419
*,
420-
timeout: int = 5, # noqa: TRIO109
420+
timeout: int = 5, # noqa: ASYNC109
421421
fswatcher_dump_file: str | None = None,
422422
) -> Response:
423423
"""Ask daemon to return status."""
@@ -433,7 +433,7 @@ async def run(
433433
status_file: str,
434434
*,
435435
flags: list[str],
436-
timeout: int | None = None, # noqa: TRIO109
436+
timeout: int | None = None, # noqa: ASYNC109
437437
daemon_timeout: int = 0,
438438
log_file: str | None = None,
439439
export_types: bool = False,
@@ -495,7 +495,7 @@ async def check(
495495
status_file: str,
496496
files: Sequence[str],
497497
*,
498-
timeout: int | None = None, # noqa: TRIO109
498+
timeout: int | None = None, # noqa: ASYNC109
499499
export_types: bool = False,
500500
) -> Response:
501501
"""Ask the daemon to check a list of files."""
@@ -512,7 +512,7 @@ async def recheck(
512512
status_file: str,
513513
export_types: bool,
514514
*,
515-
timeout: int | None = None, # noqa: TRIO109
515+
timeout: int | None = None, # noqa: ASYNC109
516516
remove: list[str] | None = None,
517517
update: list[str] | None = None,
518518
) -> Response:
@@ -551,7 +551,7 @@ async def inspect(
551551
location: str, # line:col
552552
show: str = "type", # type, attrs, definition
553553
*,
554-
timeout: int | None = None, # noqa: TRIO109
554+
timeout: int | None = None, # noqa: ASYNC109
555555
verbosity: int = 0,
556556
limit: int = 0,
557557
include_span: bool = False,
@@ -582,7 +582,7 @@ async def suggest(
582582
function: str,
583583
do_json: bool,
584584
*,
585-
timeout: int | None = None, # noqa: TRIO109
585+
timeout: int | None = None, # noqa: ASYNC109
586586
callsites: bool = False,
587587
no_errors: bool = False,
588588
no_any: bool = False,
@@ -609,7 +609,7 @@ async def suggest(
609609
async def hang(
610610
status_file: str,
611611
*,
612-
timeout: int = 1, # noqa: TRIO109
612+
timeout: int = 1, # noqa: ASYNC109
613613
) -> Response:
614614
"""Hang for 100 seconds, as a debug hack."""
615615
if not isinstance(timeout, int):

src/idlemypyextension/extension.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import annotations
66

77
# IDLE Mypy daemon integration extension
8-
# Copyright (C) 2023 CoolCat467
8+
# Copyright (C) 2023-2024 CoolCat467
99
#
1010
# This program is free software: you can redistribute it and/or modify
1111
# it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@
3434
from idlelib.config import idleConf
3535
from typing import TYPE_CHECKING, Any, ClassVar, Final
3636

37-
from idlemypyextension import annotate, client, tktrio, utils
37+
from idlemypyextension import annotate, client, mttkinter, tktrio, utils
3838

3939
if TYPE_CHECKING:
4040
from collections.abc import Callable
@@ -759,6 +759,8 @@ def unregister_async_events(self) -> None:
759759
def close(self) -> None:
760760
"""Extension cleanup before IDLE window closes."""
761761
# Wrapped in try except so failure doesn't cause zombie windows.
762+
del self.triorun
763+
mttkinter.restore()
762764
try:
763765
self.unregister_async_events()
764766
except Exception as exc:

src/idlemypyextension/mttkinter.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,24 @@ def _check_events(tk: Tk) -> None:
277277
tk.after(tk_obj._check_period, _check_events, tk)
278278

279279

280+
def restore() -> None:
281+
"""Restore original functions."""
282+
if hasattr(Tk, "__original__init__mtTkinter"):
283+
Tk.__init__ = Tk.__original__init__mtTkinter
284+
del Tk.__original__init__mtTkinter
285+
286+
if hasattr(Tk, "__original__destroy"):
287+
Tk.destroy = Tk.__original__destroy
288+
del Tk.__original__destroy
289+
290+
280291
"""Perform in-memory modification of Tkinter module"""
281292
# Replace Tk's original __init__ with the hook.
282-
Tk.__original__init__mtTkinter = Tk.__init__ # type: ignore[attr-defined]
283-
Tk.__init__ = _tk__init__ # type: ignore[ method-assign]
293+
if not hasattr(Tk, "__original__init__mtTkinter"):
294+
Tk.__original__init__mtTkinter = Tk.__init__ # type: ignore[attr-defined]
295+
Tk.__init__ = _tk__init__ # type: ignore[ method-assign]
284296

285297
# Replace Tk's original destroy with the hook.
286-
Tk.__original__destroy = Tk.destroy # type: ignore[attr-defined]
287-
Tk.destroy = _tk_destroy # type: ignore[ method-assign]
298+
if not hasattr(Tk, "__original__destroy"):
299+
Tk.__original__destroy = Tk.destroy # type: ignore[attr-defined]
300+
Tk.destroy = _tk_destroy # type: ignore[ method-assign]

src/idlemypyextension/tktrio.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ def __new__(
166166
if not is_tk_wm_and_misc_subclass(root):
167167
raise ValueError("Must be subclass of both tk.Misc and tk.Wm")
168168
ref = getattr(root, "__trio__", None)
169+
169170
if ref is not None:
170-
obj = ref()
171-
if isinstance(obj, cls):
172-
return obj
171+
return ref()
173172
return super().__new__(cls)
174173

175174
def __init__(

tests/test_annotate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import TYPE_CHECKING
99

1010
import pytest
11+
1112
from idlemypyextension import annotate
1213

1314
if TYPE_CHECKING:

tests/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import pytest
4+
45
from idlemypyextension import utils
56

67

0 commit comments

Comments
 (0)