fix(streaming): remove unreachable dead code in error handling #2820
+34
−62
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.
Summary
Removes unreachable dead code in
_streaming.pythat was caused by a logical impossibility in the conditional checks.Fixes #2796
Problem
The check
sse.event == "error"was inside a block that requiressse.event.startswith("thread."):Since
"error"does not start with"thread.", this condition can never be true, making the entire error handling block dead code.Solution
Restructured the code to:
thread.*event special case for the yieldThis removes ~28 lines of dead code while preserving all intended functionality. The error handling now works correctly for all SSE events, not just theoretically for
thread.*events.Changes
src/openai/_streaming.py: Fixed bothStream(sync) andAsyncStream(async) classesTest plan
data.get("error"))thread.*events still get wrapped with{"data": data, "event": sse.event}datadirectly🤖 Generated with Claude Code