Skip to content

Commit

Permalink
Fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 committed Jan 17, 2025
1 parent 6b0edcb commit 39ada8b
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/idlemypyextension/tktrio.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,11 @@ def evil_does_trio_have_runner() -> bool: # pragma: nocover
return hasattr(global_run_context, "runner")


class TKMiscWmSubclass(tk.Misc, tk.Wm):
"""Subclass of both tkinter Misc and tkinter Wm."""

__slots__ = ()


def is_tk_wm_and_misc_subclass(
val: tk.Tk | tk.BaseWidget | tk.Wm | tk.Misc,
) -> TypeGuard[TKMiscWmSubclass]:
"""Return if value is an instance of both tk.Misc and tk.Wm."""
return isinstance(val, tk.Misc) and isinstance(val, tk.Wm)
val: tk.Toplevel | tk.Tk | object,
) -> TypeGuard[tk.Toplevel | tk.Tk]:
"""Return if value is an instance of tk.Toplevel."""
return isinstance(val, tk.Toplevel | tk.Tk)


class TkTrioRunner:
Expand All @@ -161,7 +155,7 @@ class TkTrioRunner:

def __new__(
cls,
root: tk.Wm | tk.Misc,
root: tk.Toplevel | tk.Tk,
*args: Any,
**kwargs: Any,
) -> Self:
Expand All @@ -181,7 +175,7 @@ def __new__(

def __init__(
self,
root: tk.Wm | tk.Misc,
root: tk.Toplevel | tk.Tk,
restore_close: Callable[[], Any] | None = None,
) -> None:
"""Initialize trio runner."""
Expand All @@ -199,7 +193,7 @@ def __init__(
self.installed_proto_override = False

with contextlib.suppress(AttributeError):
root.__trio__ = weakref.ref(self) # type: ignore[attr-defined]
root.__trio__ = weakref.ref(self) # type: ignore[union-attr]

def schedule_task_threadsafe(
self,
Expand Down Expand Up @@ -473,7 +467,7 @@ async def trio_test_program(run: int) -> str:
raise
return "trio done!"

root = tk.Tk(className="Trio Test")
root = tk.Tk()

def trigger_trio_runs() -> None:
trio_run = TkTrioRunner(root)
Expand Down

0 comments on commit 39ada8b

Please sign in to comment.