Python: fix(core): treat a missing text delta as empty when adding text content - #8699
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits intoSep 29, 2026
Conversation
…xt content
`text` is optional on a text content, but `_add_text_content` concatenated
`self.text + other.text` directly, so a part with no text raised
`TypeError: can only concatenate str (not "NoneType") to str`.
This is reachable from the public API: `_coalesce_text_content` merges
consecutive text contents with `+`, so one such part aborts the whole
response.
ChatResponse.from_updates([
ChatResponseUpdate(role="assistant", contents=[Content("text", text="Hello ")]),
ChatResponseUpdate(role="assistant", contents=[Content("text")]),
ChatResponseUpdate(role="assistant", contents=[Content("text", text="world")]),
]) # TypeError
The same stream built from `text_reasoning` parts already worked, because
`_add_text_reasoning_content` does handle it. This makes the two agree:
a missing delta counts as empty, and `None` survives only when neither side
has text, so it stays distinguishable from a real empty string.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WyCUJcDPnCnQMmuDwsnDmD
Anish Mehta (anishmehta24)
deployed
to
github-app-auth
September 23, 2026 15:39 — with
GitHub Actions
Active
Anish Mehta (anishmehta24)
deployed
to
github-app-auth
September 23, 2026 15:39 — with
GitHub Actions
Active
Anish Mehta (anishmehta24)
deployed
to
github-app-auth
September 24, 2026 11:59 — with
GitHub Actions
Active
Anish Mehta (anishmehta24)
deployed
to
github-app-auth
September 29, 2026 04:44 — with
GitHub Actions
Active
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Sep 29, 2026
Eduard van Valkenburg (eavanvalkenburg)
left a comment
Member
There was a problem hiding this comment.
Anish Mehta (@anishmehta24) Reviewed the current head and found no blocking issues.
This branch was successfully deployed
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.
Motivation and Context
textis optional on a text content —Content("text")andContent.from_dict({"type": "text"})both produce one withtext=None, andtest_chat_response_value_handles_text_content_without_textalready covers that shape existing. But_add_text_contentconcatenates the attributes directly:so adding one raises
TypeError: can only concatenate str (not "NoneType") to str.That's reachable from the public API rather than just from
+._coalesce_text_contentmerges consecutive text contents with+during_finalize_response, so a single text part carrying no delta (annotations or metadata only) takes down the whole response:The same stream built out of
text_reasoningparts returns"Hello world"and always has, because_add_text_reasoning_contenthandles this case deliberately — there's a comment there about Anthropic emitting a thinking block withthinking="". The two content types just disagreed about what a missing value means.Description
_add_text_contentnow follows the same rule as its reasoning counterpart: a missing delta counts as empty, andNonesurvives only when neither side has text. That keepsNone(no text) distinguishable from""(an empty one), which matters for the same replay reason as in the reasoning path.One line of behaviour change, no signature change. The
# type: ignore[operator]comment is gone too, since the operands are strings now.Contribution Checklist
Tests in
packages/core/tests/core/test_types.py:test_text_content_add_handles_missing_text— adding in either directiontest_text_content_add_preserves_none_and_empty_string—None + NonestaysNone,"" + Nonestays""test_chat_response_from_updates_coalesces_text_update_without_text— the reachable path, assertingtextandtext_reasoningnow behave the sameAll three fail on
main.tests/core/test_types.pypasses in full, and the wholetests/coredirectory is green.ruff checkandruff formatclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01WyCUJcDPnCnQMmuDwsnDmD