fix: raise TypeError for unrecognised MIDI messages in normalize_midi_messages - #495
Open
steps-re wants to merge 1 commit into
Open
fix: raise TypeError for unrecognised MIDI messages in normalize_midi_messages#495steps-re wants to merge 1 commit into
steps-re wants to merge 1 commit into
Conversation
…_messages normalize_midi_messages() was silently dropping any MIDI message that did not match the expected (bytes, float) tuple or duck-typed mido.Message shape. Silent data loss made it impossible to detect malformed input — e.g. a 1-tuple with a missing timestamp — without manually comparing input and output lengths. Switch the `for` loop to use `enumerate()` and add an `else` branch that raises TypeError with the offending index and value, consistent with the ValueError already raised for timestamp heuristics. Fixes spotify#489 Signed-off-by: Mike German <mike@stepsventures.com>
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.
Fixes #489.
normalize_midi_messages()used anif / elifchain with noelsebranch, so any message that did not match the expected(bytes, float)tuple shape or a duck-typedmido.Messagewas silently dropped. The caller received a shorter output list with no indication that events were lost — wrong tuple length, missing timestamp, rawbytes,None, etc. all vanished without error.Change:
forloop toenumerate()to track the message index.elsebranch that raisesTypeErrorwith the offending index and value.Test:
Added
test_normalize_midi_messages_raises_on_malformedintests/test_midi_utils.py, covering five malformed shapes: 1-tuple (missing timestamp), 3-tuple (extra field), rawbytes, bare integer, andNone.