Skip to content

refactor: consolidate __init__, _build_stream_metadata, _parse_output into base Stream#172

Merged
Kamilbenkirane merged 1 commit intomainfrom
refactor/consolidate-stream-init-metadata-parse-output
Feb 23, 2026
Merged

refactor: consolidate __init__, _build_stream_metadata, _parse_output into base Stream#172
Kamilbenkirane merged 1 commit intomainfrom
refactor/consolidate-stream-init-metadata-parse-output

Conversation

@Kamilbenkirane
Copy link
Member

Summary

Closes #169

  • Move __init__, _build_stream_metadata, and _parse_output from TextStream, ImagesStream, and AudioStream into the base Stream class
  • Replace client=self with stream_metadata={...} dict — streams no longer hold a client reference
  • Add _output_class ClassVar and abstract _aggregate_content to base Stream
  • Convert _map_output_format_to_mime_type to @staticmethod on ElevenLabs/Gradium provider mixins (pure functions that never used self)
  • Each modality stream reduces to ~10-15 lines (ClassVars + _aggregate_content)

~115 net lines removed across 12 files with zero behavioral changes.

Test plan

  • pytest tests/unit_tests/test_streaming.py — 30 base streaming tests pass
  • pytest tests/unit_tests/test_stream_metadata_from_response_data.py — 4 metadata tests pass
  • pytest tests/unit_tests/ — full 474 unit tests pass
  • All pre-commit hooks pass (ruff lint, ruff format, mypy, bandit)
  • All pre-push hooks pass (tests with coverage)
  • 3 rounds of exhaustive codebase verification: zero stale self._client, client=, or ModalityClient references in stream contexts

… into base Stream (#169)

Move three duplicated methods from TextStream, ImagesStream, and AudioStream
into the base Stream class:

- __init__: absorb transform_output and stream_metadata params (replaces client ref)
- _build_stream_metadata: base now merges stream_metadata dict with raw_events
- _parse_output: concrete default using new _aggregate_content abstract + _output_class ClassVar

Also convert _map_output_format_to_mime_type to @staticmethod on ElevenLabs/Gradium
provider mixins since the stream no longer holds a client reference.

~140 lines removed across 12 files with zero behavioral changes.
@claude
Copy link

claude bot commented Feb 23, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@Kamilbenkirane Kamilbenkirane merged commit c3fd9e3 into main Feb 23, 2026
11 checks passed
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.

Consolidate __init__, _build_stream_metadata, _parse_output into base Stream class

1 participant