fix: raise TypeError for unrecognised messages in normalize_midi_messages - #490
Open
m-zandi wants to merge 2 commits into
Open
fix: raise TypeError for unrecognised messages in normalize_midi_messages#490m-zandi wants to merge 2 commits into
m-zandi wants to merge 2 commits into
Conversation
…ages Previously, any message that did not match the expected formats (mido-style object or 2-tuple) was silently dropped. This caused silent data loss that was impossible to detect without manually comparing input and output lengths. The fix adds an `else` branch that raises TypeError immediately, including the index and repr of the offending element so callers can identify and correct their data. Closes spotify#489
Covers spotify#489 — ensures malformed messages raise TypeError rather than being silently discarded.
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.
What this PR does
Fixes the silent data-loss bug in
normalize_midi_messages()whereunrecognised MIDI messages (wrong tuple length, bare bytes, unknown type,
etc.) were silently dropped from the output list.
Changes
pedalboard/midi_utils.py— Addedelsebranch that raisesTypeErrorwith the index and repr of the offending element, so callers get an
immediate, actionable error instead of a shorter-than-expected list.
tests/test_midi_utils.py— Added parametrized regression tests covering1-tuples, 3-tuples, bare bytes, bare integers, and
None.Closes
Closes #489
How to test
All new tests should pass. The existing
test_mido_normalizationtest isunaffected.
Before / After
Before:
After: