Skip to content

fix(streaming): align non-beta accumulator with beta implementation#1586

Open
xodn348 wants to merge 1 commit into
anthropics:mainfrom
xodn348:fix/streaming-accumulator-consistency
Open

fix(streaming): align non-beta accumulator with beta implementation#1586
xodn348 wants to merge 1 commit into
anthropics:mainfrom
xodn348:fix/streaming-accumulator-consistency

Conversation

@xodn348
Copy link
Copy Markdown
Contributor

@xodn348 xodn348 commented May 22, 2026

What

Fixes three inconsistencies between _messages.py (non-beta) and _beta_messages.py (beta) in the streaming accumulator:

  1. model_dump()to_dict() in the content_block_start handler — to_dict() defaults to use_api_names=True and exclude_unset=True, which is correct for construct_type() and consistent with both the message_start handler in the same file (line 452) and the beta version.

  2. type(event)builtins.type(event) in the error path — prevents potential shadowing of the type builtin, matching the beta implementation.

  3. ryeuv shebang in examples/messages_stream.py — the only example still referencing rye after the project migrated to uv (per CONTRIBUTING.md line 52).

Why

The beta streaming accumulator appears to have received these fixes independently, but the non-beta version was not updated to match. The model_dump() vs to_dict() difference is the most significant: if a content block type ever introduces field aliasing, model_dump() would pass Python-style keys while construct_type() expects API-style keys, causing silent field drops.

Verification

  • Build: pass
  • Tests: pass (31 passed — 13 non-beta + 18 beta streaming tests)
  • Lint: pass (ruff)
  • Type check: pass (pyright 0 errors, mypy 0 errors)

- Use to_dict() instead of model_dump() in content_block_start handler
  to match the beta version and the message_start handler in the same file.
  to_dict() uses API-compatible key names (use_api_names=True) and excludes
  unset fields by default, which is the correct behavior for construct_type().

- Use builtins.type() instead of bare type() in the error message to prevent
  potential shadowing, consistent with the beta implementation.

- Update messages_stream.py shebang from rye to uv, consistent with all
  other examples and CONTRIBUTING.md guidelines.
@xodn348 xodn348 requested a review from a team as a code owner May 22, 2026 05:16
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