Skip to content

feat(types): add __repr__ to content block and message types#867

Open
xodn348 wants to merge 3 commits intoanthropics:mainfrom
xodn348:feat/message-repr
Open

feat(types): add __repr__ to content block and message types#867
xodn348 wants to merge 3 commits intoanthropics:mainfrom
xodn348:feat/message-repr

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented Apr 23, 2026

Closes #78

What changed

Added __repr__ methods to all content block and message types in src/claude_agent_sdk/types.py.

Types updated (17 total)

Content blocks: TextBlock, ThinkingBlock, ToolUseBlock, ToolResultBlock, ServerToolUseBlock, ServerToolResultBlock

Messages: UserMessage, AssistantMessage, SystemMessage, ResultMessage

Events: TaskStartedMessage, TaskProgressMessage, TaskNotificationMessage, MirrorErrorMessage, StreamEvent, RateLimitInfo, RateLimitEvent

Implementation details

  • Added _truncate(s, max_len=100) module-level helper to bound long fields
  • All __repr__ methods return concise single-line strings showing key fields
  • Long string fields (text, thinking, error) are truncated at 100 chars
  • Dict/list fields use _truncate(repr(field)) for safety
  • UserMessage handles str | list[ContentBlock] union with isinstance check
  • All methods have -> str return annotation (mypy strict compatible)

Tests

Added class TestRepr with 18 test methods in tests/test_types.py.
All 63 tests pass (pytest tests/test_types.py -v).

xodn348 and others added 3 commits April 22, 2026 23:45
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.

Support reprs for message types

1 participant