Skip to content

Commit 6f73121

Browse files
Kasper JungeRalphify
authored andcommitted
refactor: clarify naming and eliminate docstring duplication
Rename _get_run → _require_run in RunManager to distinguish it from the public get_run (returns None). The "require" name makes the KeyError-raising behavior obvious at call sites. Move the shared returncode/timed_out field documentation from RunResult and AgentResult into the base ProcessResult class where it belongs, eliminating identical docstrings in both subclasses. Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent f2b7a17 commit 6f73121

4 files changed

Lines changed: 10 additions & 16 deletions

File tree

src/ralphify/_agent.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@
4646

4747
@dataclass
4848
class AgentResult(ProcessResult):
49-
"""Result of running the agent subprocess.
50-
51-
*returncode* is the process exit code, or ``None`` when the process
52-
timed out. *timed_out* makes the timeout condition explicit — prefer
53-
checking ``timed_out`` over ``returncode is None``.
54-
"""
49+
"""Result of running the agent subprocess."""
5550

5651
elapsed: float = 0.0
5752
log_file: Path | None = None

src/ralphify/_output.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class ProcessResult:
2222
Shared by :class:`~ralphify._runner.RunResult` and
2323
:class:`~ralphify._agent.AgentResult` so the common *success*
2424
logic lives in one place.
25+
26+
*returncode* is the process exit code, or ``None`` when the process
27+
timed out. *timed_out* makes the timeout condition explicit — prefer
28+
checking ``timed_out`` over ``returncode is None``.
2529
"""
2630

2731
returncode: int | None

src/ralphify/_runner.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@
1818

1919
@dataclass
2020
class RunResult(ProcessResult):
21-
"""Result of running a command or script.
22-
23-
*returncode* is the process exit code, or ``None`` when the process
24-
timed out. *timed_out* makes the timeout condition explicit — prefer
25-
checking ``timed_out`` over ``returncode is None``.
26-
"""
21+
"""Result of running a command or script."""
2722

2823
output: str = ""
2924

src/ralphify/manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _lookup(self, run_id: str) -> ManagedRun:
6767
except KeyError:
6868
raise KeyError(f"No run with ID '{run_id}'") from None
6969

70-
def _get_run(self, run_id: str) -> ManagedRun:
70+
def _require_run(self, run_id: str) -> ManagedRun:
7171
"""Look up a run by ID under the lock. Raises ``KeyError`` if missing."""
7272
with self._lock:
7373
return self._lookup(run_id)
@@ -114,15 +114,15 @@ def start_run(self, run_id: str) -> None:
114114

115115
def stop_run(self, run_id: str) -> None:
116116
"""Signal the run to stop after the current iteration finishes."""
117-
self._get_run(run_id).state.request_stop()
117+
self._require_run(run_id).state.request_stop()
118118

119119
def pause_run(self, run_id: str) -> None:
120120
"""Pause the run between iterations until :meth:`resume_run` is called."""
121-
self._get_run(run_id).state.request_pause()
121+
self._require_run(run_id).state.request_pause()
122122

123123
def resume_run(self, run_id: str) -> None:
124124
"""Resume a paused run."""
125-
self._get_run(run_id).state.request_resume()
125+
self._require_run(run_id).state.request_resume()
126126

127127
def list_runs(self) -> list[ManagedRun]:
128128
"""Return a snapshot of all registered runs."""

0 commit comments

Comments
 (0)