Resolve decode_state's field types from string annotations too
This commit was merged in pull request #122.
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import typing
|
||||
|
||||
RELOAD_FLAG = "--reloaded"
|
||||
|
||||
@@ -13,7 +14,7 @@ def decode_state(handed, kind):
|
||||
fields = json.loads(handed)
|
||||
except ValueError:
|
||||
return None
|
||||
shape = {field.name: field.type for field in dataclasses.fields(kind)}
|
||||
shape = typing.get_type_hints(kind)
|
||||
if not isinstance(fields, dict) or fields.keys() != shape.keys():
|
||||
return None
|
||||
if any(type(fields[name]) is not type_ for name, type_ in shape.items()):
|
||||
|
||||
+10
-1
@@ -1,3 +1,4 @@
|
||||
import dataclasses
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
@@ -7,7 +8,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
|
||||
from loop_claude import file_writes, main
|
||||
from loop_claude import file_writes, main, reload
|
||||
from loop_claude.claude_code import formats, transcript
|
||||
from loop_claude.claude_runs import judge
|
||||
from loop_claude.outcome import Failure, Stop
|
||||
@@ -119,6 +120,14 @@ class LoopState(unittest.TestCase):
|
||||
with self.subTest(handed=handed):
|
||||
self.assertEqual(main.loop_state([main.RELOAD_FLAG, *handed], CWD), Stop(1, f"the reload cannot read the loop's state from {handed}; rerun loop-claude <task>"))
|
||||
|
||||
def test_decodes_a_state_whose_annotations_are_strings(self):
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Stringly:
|
||||
count: "int"
|
||||
name: "str"
|
||||
self.assertEqual(reload.decode_state('{"count": 1, "name": "n"}', Stringly), Stringly(1, "n"))
|
||||
self.assertIsNone(reload.decode_state('{"count": "1", "name": "n"}', Stringly))
|
||||
|
||||
|
||||
|
||||
class ReplaceFile(unittest.TestCase):
|
||||
|
||||
@@ -8,7 +8,6 @@ The rebuild lifts every dimension, one chunk per item, until the last item opens
|
||||
|
||||
The places the panel on `rebuild` at 7f9de5c named (`docs/decisions.md`), capping dimension first:
|
||||
|
||||
- **Make `decode_state` check the fields' types without relying on the annotations being runtime types.** Two seats: `from __future__ import annotations` in `main.py` would fail every reload.
|
||||
- **State once, in `outcome.py`, that a `Failure` is retried and a `Stop` exits.** Three seats inferred it from `run_loop`.
|
||||
- **Define a round once, in larv-review's "Round cap", and link it from `review-findings.md` → "Rounds", the Vocabulary and the auto-reviewer's step.** All four seats held §3, "Rounds" and the Vocabulary open together to settle whether a launch counts.
|
||||
- **Give `project` one meaning: rename `Paths.projects` and `Session.projects` for Claude Code's transcript directory.** Two seats: it also names the package, the key and `~/.claude.json`'s object.
|
||||
|
||||
Reference in New Issue
Block a user