Skip to content

(AI) Order TimespanTree.allParts() by the source score - #2089

Merged
mscuthbert merged 1 commit into
cuthbertLab:masterfrom
syahra712:fix-2074-allparts-order
Oct 19, 2026
Merged

mscuthbert merged 1 commit into
cuthbertLab:masterfrom
syahra712:fix-2074-allparts-order

Conversation

@syahra712

Copy link
Copy Markdown
Contributor

Fixes #2074. TimespanTree.allParts() sorted parts by getInstrument().partId. Parts without a partId, which is common for MIDI imports, made ChordReducer.run() raise TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'.

As the issue suggests, allParts() now returns the parts in the order they appear in the tree's source when the source has parts, such as a Score. Any other parts come after them, sorted by partId, and a missing partId no longer breaks the sort. This also matters for ChordReducer.splitByBass(), which takes the last part as the bass: a string sort on partId put P10 before P2.

Tests:

  • A doctest on allParts().
  • testPartsWithoutPartId runs the example from the issue through ChordReducer().run().
  • testPartsOrderedAsInScore covers partIds that don't sort in score order.
  • The timespanTree and reduceChords module tests pass, including the bwv66.6 doctests, whose part order is unchanged. Pylint is 10/10.

AI-assisted (Claude). I reviewed the code and ran the tests.

allParts() sorted the parts by their instrument's partId, which raised a
TypeError when the parts had no partId (as with MIDI imports) and put
P10 before P2. Use the order of the parts in the source score instead,
falling back to partId for parts that are not in the source.

Fixes cuthbertLab#2074
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 93.381% (+0.002%) from 93.379% — syahra712:fix-2074-allparts-order into cuthbertLab:master

@mscuthbert

Copy link
Copy Markdown
Member

thanks! looks good.

we're moving more towards isinstance Part checking rather than hasattr checking for things like .parts but fine to keep here.

@mscuthbert
mscuthbert merged commit 1b094a1 into cuthbertLab:master Oct 19, 2026
8 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.

TypeError in ChordReducer.run() on multi-part stream.Score without instrument partIds

3 participants