Skip to content

fix: resolve mypy shape-type error in _frames_to_mono_i16#9

Merged
munkhorgil merged 1 commit into
mainfrom
fix/recorder-mono-reshape-mypy
Jul 2, 2026
Merged

fix: resolve mypy shape-type error in _frames_to_mono_i16#9
munkhorgil merged 1 commit into
mainfrom
fix/recorder-mono-reshape-mypy

Conversation

@munkhorgil

Copy link
Copy Markdown
Collaborator

What

Fixes a mypy failure in _recorder.py that broke CI:

src/roark_analytics_python_livekit/_recorder.py:46: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], ...]", variable has type "ndarray[tuple[int], ...]")  [assignment]

numpy's shape-parameterized stubs track array rank in the type. In _frames_to_mono_i16, arr starts as a 1-D int16 array from np.frombuffer, so reassigning the 2-D reshape(-1, num_channels) result back onto it is a rank conflict.

Changes

  • Move the multi-channel 2-D view into its own multi variable so arr stays 1-D throughout. No runtime behavior change — still averages interleaved channels down to mono int16.

Verification

  • uv run mypy src/roark_analytics_python_livekitSuccess: no issues found in 6 source files
  • uv run ruff check . → clean
  • uv run pytest → 34 passed

numpy's shape-parameterized stubs rejected reassigning the 2-D reshape
result back onto the 1-D int16 array. Use a separate variable for the
multi-channel view so the mono array stays 1-D. No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Jul 2, 2026

Copy link
Copy Markdown

Claude finished @munkhorgil's task in 1m 23s —— View job


Code review complete

  • Gather context (diff, file contents)
  • Understand the request (code review)
  • Review code quality, security, performance, testing, docs
  • Post summary review

Code Review Summary

Category Score Notes
Code Quality 5/5 Minimal, correct fix — keeps arr rank-stable by introducing multi for the 2-D view
Security 5/5 No security surface touched
Performance 5/5 No behavior/perf change — same numpy ops, no extra copies
Testing 5/5 Existing test_frames_to_mono_stereo_averages_channels in tests/test_recorder.py already exercises this exact multi-channel path and passes unchanged
Documentation 5/5 N/A — no public API/behavior change
Overall 5/5

Findings

None. The change in src/roark_analytics_python_livekit/_recorder.py:46-47:

multi = arr.reshape(-1, f.num_channels)
arr = (multi.astype(np.int32).sum(axis=1) // f.num_channels).astype(np.int16)

correctly resolves the mypy shape-rank conflict (numpy's shape-parameterized stubs treat arr.reshape(-1, n) as a different rank than the original 1-D arr, so reassigning onto the same variable was a type error) by giving the intermediate 2-D view its own name. arr stays 1-D int16 throughout, matching the function's declared return type. Confirmed reshape is used nowhere else in the codebase, so this was the only site affected.

Nice, surgical fix — appropriately scoped to just the mypy failure with no unrelated changes.

@munkhorgil munkhorgil merged commit 49dcf5a into main Jul 2, 2026
6 checks passed
@munkhorgil munkhorgil deleted the fix/recorder-mono-reshape-mypy branch July 2, 2026 07:11
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.

1 participant