Skip to content

fix: align _parse_usage return types with RawUsage contract#174

Merged
Kamilbenkirane merged 2 commits intomainfrom
fix/parse-usage-raw-usage-contract
Feb 23, 2026
Merged

fix: align _parse_usage return types with RawUsage contract#174
Kamilbenkirane merged 2 commits intomainfrom
fix/parse-usage-raw-usage-contract

Conversation

@Kamilbenkirane
Copy link
Member

Summary

  • Three modality-level _parse_usage overrides returned typed ImageUsage objects instead of RawUsage dicts, causing _get_usage() to crash with ImageUsage() argument after ** must be a mapping, not ImageUsage on Gemini/Imagen image generation
  • Removed redundant _parse_usage and _parse_finish_reason overrides from the modality template — _get_usage/_get_finish_reason in APIMixin already handle raw → typed conversion via _usage_class/_finish_reason_class ClassVars

Test plan

  • All 474 unit tests pass
  • All pre-commit hooks pass (ruff, mypy, bandit)
  • All pre-push hooks pass (tests with coverage)
  • Manual: verify Gemini image generation no longer crashes

Closes #173

Three modality-level _parse_usage overrides returned typed ImageUsage
objects instead of dicts, causing _get_usage() to crash with
"argument after ** must be a mapping, not ImageUsage".

Also remove redundant _parse_usage and _parse_finish_reason overrides
from the modality template — _get_usage/_get_finish_reason in APIMixin
already handle the raw → typed conversion via ClassVars.

Closes #173
- Use UsageField.NUM_IMAGES constant instead of raw "num_images" string
- Add regression tests for _parse_usage dict return type contract
- Fix ConcreteModalityClient test helper (same Usage() → {} bug)
- Restore _parse_finish_reason scaffold in modality template
@Kamilbenkirane Kamilbenkirane merged commit 4992573 into main Feb 23, 2026
11 checks passed
@claude
Copy link

claude bot commented Feb 23, 2026

Code review

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

@Kamilbenkirane Kamilbenkirane mentioned this pull request Feb 24, 2026
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.

fix: _parse_usage returns typed ImageUsage instead of RawUsage dict

1 participant