Skip to content

Decode input with msgspec instead of a hand-coded constructor - #18

Merged
jhidding merged 2 commits into
mainfrom
msgspec-construct
Nov 16, 2026
Merged

jhidding merged 2 commits into
mainfrom
msgspec-construct

Conversation

@jhidding

@jhidding jhidding commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Replaces the hand-written type walker in brei/construct.py with msgspec.convert, following the same approach as Entangled.

  • construct(annot, data) is now a thin wrapper around msgspec.convert that turns a ValidationError into an InputError. read_from_file adds the file name to the error.
  • Program, TaskProxy, TemplateCall and Runner are now msgspec.Struct classes with forbid_unknown_fields=True, so a typo such as requries = [...] is reported instead of ignored. substitute and gather_args handle Structs as well as dataclasses.
  • Join uses the string values "inner"/"outer", because msgspec matches enums by value. This is now case sensitive.
  • FromStr is removed; only Phony used it, and only through the old decoder.
  • The CLI catches InputError, so bad input is shown as an error message instead of a traceback, for example:
    In `bad.toml`: Invalid input for `Program`: Object contains unknown field `requries` - at `$.task[0]`
    
  • Adds msgspec>=0.20.0 as a runtime dependency (and entangled-cli as a dev dependency).

The .py files are tangled from the literate sources in docs/. Also includes a small commit fixing pyright errors.

This is the first of three stacked PRs; the next one builds on this branch.

🤖 Generated with Claude Code

jhidding and others added 2 commits November 16, 2026 08:02
Replace the hand-written type walker in `construct` with
`msgspec.convert`. The input classes (`Program`, `TaskProxy`/`Template`,
`TemplateCall`, `Runner`) are now msgspec Structs with
`forbid_unknown_fields=True`, so typos in field names are reported.
`Join` uses string values, and `FromStr` is removed.

Input errors now report the file and location of the problem, and the
CLI prints them as a regular error instead of a traceback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jhidding
jhidding merged commit 53af47b into main Nov 16, 2026
0 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant