Skip to content

Commit 1545ee4

Browse files
Kasper JungeRalphify
authored andcommitted
refactor: replace manual __slots__ classes with @DataClass(slots=True)
Convert _ToolConfig and _ScrollbarMetrics from hand-written __slots__ classes to @DataClass(slots=True) for consistency with the rest of the codebase and reduced boilerplate. Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent 318f772 commit 1545ee4

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/ralphify/_console_emitter.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import threading
1212
import time
1313
from collections.abc import Callable
14+
from dataclasses import dataclass
1415
from functools import partial
1516
from pathlib import Path
1617
from typing import Any
@@ -221,20 +222,13 @@ def _format_run_info(
221222
# lavender=web, violet=delegate, purple=meta.
222223

223224

225+
@dataclass(slots=True)
224226
class _ToolConfig:
225227
"""Visual and extraction config for a known tool."""
226228

227-
__slots__ = ("color", "category", "extract_arg")
228-
229-
def __init__(
230-
self,
231-
color: str,
232-
category: str,
233-
extract_arg: Callable[[dict[str, Any]], str] | None = None,
234-
) -> None:
235-
self.color = color
236-
self.category = category
237-
self.extract_arg = extract_arg
229+
color: str
230+
category: str
231+
extract_arg: Callable[[dict[str, Any]], str] | None = None
238232

239233

240234
_TOOL_REGISTRY: dict[str, _ToolConfig] = {
@@ -248,10 +242,18 @@ def __init__(
248242
"BashOutput": _ToolConfig(_brand.GREEN, "bash"),
249243
"WebFetch": _ToolConfig(_brand.LAVENDER, "web", lambda i: i.get("url", "")),
250244
"WebSearch": _ToolConfig(_brand.LAVENDER, "web", lambda i: i.get("query", "")),
251-
"Task": _ToolConfig(_brand.VIOLET, "task", lambda i: _format_params(i, ["description", "prompt"])),
252-
"Agent": _ToolConfig(_brand.VIOLET, "agent", lambda i: _format_params(i, ["description", "prompt"])),
253-
"ToolSearch": _ToolConfig(_brand.BLUE, "other", lambda i: _format_params(i, ["query", "max_results"])),
254-
"TodoWrite": _ToolConfig(_brand.PURPLE, "todo", lambda i: f"{len(i.get('todos', []))} todos"),
245+
"Task": _ToolConfig(
246+
_brand.VIOLET, "task", lambda i: _format_params(i, ["description", "prompt"])
247+
),
248+
"Agent": _ToolConfig(
249+
_brand.VIOLET, "agent", lambda i: _format_params(i, ["description", "prompt"])
250+
),
251+
"ToolSearch": _ToolConfig(
252+
_brand.BLUE, "other", lambda i: _format_params(i, ["query", "max_results"])
253+
),
254+
"TodoWrite": _ToolConfig(
255+
_brand.PURPLE, "todo", lambda i: f"{len(i.get('todos', []))} todos"
256+
),
255257
}
256258

257259
_DEFAULT_TOOL_STYLE: tuple[str, str] = ("white", "other")
@@ -582,6 +584,7 @@ def _build_footer(self) -> Table:
582584
_FULLSCREEN_MIN_VISIBLE = 5
583585

584586

587+
@dataclass(slots=True)
585588
class _ScrollbarMetrics:
586589
"""Pure-data result of scrollbar geometry calculation.
587590
@@ -591,12 +594,9 @@ class _ScrollbarMetrics:
591594
``True``.
592595
"""
593596

594-
__slots__ = ("show", "thumb_start", "thumb_size")
595-
596-
def __init__(self, show: bool, thumb_start: int, thumb_size: int) -> None:
597-
self.show = show
598-
self.thumb_start = thumb_start
599-
self.thumb_size = thumb_size
597+
show: bool
598+
thumb_start: int
599+
thumb_size: int
600600

601601

602602
def _scrollbar_metrics(total: int, visible: int, offset: int) -> _ScrollbarMetrics:

0 commit comments

Comments
 (0)