Add __repr__ to message and content block types#770
Open
kostakost2 wants to merge 1 commit intoanthropics:mainfrom
Open
Add __repr__ to message and content block types#770kostakost2 wants to merge 1 commit intoanthropics:mainfrom
kostakost2 wants to merge 1 commit intoanthropics:mainfrom
Conversation
Fixes anthropics#78. Adds human-readable __repr__ methods to all message types and content blocks so they display usefully without custom helpers: - TextBlock: shows truncated text preview - ThinkingBlock: shows truncated thinking preview - ToolUseBlock: shows tool name and input key names - ToolResultBlock: shows truncated content and error flag - UserMessage: shows content preview or block count - AssistantMessage: shows model, text preview, stop_reason - SystemMessage: shows subtype - ResultMessage: shows status, turn count and cost All 409 existing tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #78.
What this does
Adds human-readable
__repr__methods to all message types and content block dataclasses, so messages display usefully in REPLs, logs and debuggers without needing custom helpers.Before:
After:
Changes
TextBlock: truncated text preview (60 chars)ThinkingBlock: truncated thinking previewToolUseBlock: tool name + input key names (values omitted — can be large/sensitive)ToolResultBlock: truncated content preview, error flag shown when trueUserMessage: string content preview or block countAssistantMessage: model, first text block preview, stop_reason/error when setSystemMessage: subtype onlyResultMessage: status (ok/error), turn count, cost when availableTests
All 409 existing tests pass. The new reprs are purely additive — no behaviour changes.