Skip to content

fix(memo): plumb state_methods through dataclass/pydantic fields#1971

Merged
georgeh0 merged 1 commit into
mainfrom
g/memo-state-plumbing
May 12, 2026
Merged

fix(memo): plumb state_methods through dataclass/pydantic fields#1971
georgeh0 merged 1 commit into
mainfrom
g/memo-state-plumbing

Conversation

@georgeh0

Copy link
Copy Markdown
Member

Summary

  • Fix plumbing bug in _canonicalize_dataclass / _canonicalize_pydantic: they recursed via _canonicalize without forwarding state_methods, silently dropping any __coco_memo_state__ nested inside a dataclass or Pydantic field.
  • Make state_methods a required positional list[StateFnEntry] on _canonicalize, _make_call_canonical, and fingerprint_call so the bug class cannot recur — every recursive site and every public caller is forced to thread it through. Callers that don't care (e.g. memo_fingerprint, tests checking only fingerprint equality) pass [].
  • Add test_state_methods_collected_through_dataclass_field and test_state_methods_collected_through_pydantic_field covering the bug.

Test plan

CI (mypy + pytest cover the change).

`_canonicalize_dataclass` and `_canonicalize_pydantic` recursed via
`_canonicalize` without forwarding `state_methods`, so any
`__coco_memo_state__` nested inside a dataclass or Pydantic field was
silently dropped from the collected state-method list.

Make `state_methods` a required positional `list[StateFnEntry]` on
`_canonicalize`, `_make_call_canonical`, and `fingerprint_call` so every
recursive site and every public caller is forced to thread it through.
Callers that don't care (e.g. `memo_fingerprint`, tests that only check
fingerprint equality) pass a throwaway empty list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@georgeh0 georgeh0 merged commit 43df0f1 into main May 12, 2026
18 checks passed
@georgeh0 georgeh0 deleted the g/memo-state-plumbing branch May 12, 2026 15:46
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