Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`TypeError` in `ChordReducer.run()` on multi-part `stream.Score` without instrument `partId`s

Aperta Adatta ai principianti
#2,074 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
data

Direzione di ricerca

Il crash si trova in TimespanTree.allParts() in music21/tree/timespanTree.py (intorno alla riga 743), dove le parti vengono ordinate per getInstrument().partId, che può essere None. Parti da ChordReducer.run() in music21/analysis/reduceChords.pyed esegui lo script di riproduzione dell'issue. È completato quando lo script termina senza TypeError e le parti mantengono un ordine sensato, ad esempio quello in cui compaiono nella partitura. L'issue propone due ordinamenti, quindi verifica con i maintainer quale usare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

music21 version

11.0.0b11

Problem summary

ChordReducer.run() was found to raise a TypeError when given a multi-part stream.Score whose instruments were not assigned partIds.

Steps to reproduce

from music21 import chord, instrument, note, stream
from music21.analysis.reduceChords import ChordReducer

upperInstrument = instrument.Instrument()  
# upperInstrument.partId = 'P1'
lowerInstrument = instrument.Instrument()    
# lowerInstrument.partId = 'P2'

upper = stream.Part([upperInstrument, stream.Measure([chord.Chord('C4 E4', type='whole')])])                                                                                               
lower = stream.Part([lowerInstrument, stream.Measure([note.Note('G4', type='whole')])])                                                                                                    

score = stream.Score([upper, lower])                                                                                                                            
ChordReducer().run(score)
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'

This error was discovered when calling ChordReducer.run() on scores loaded from MIDI.

Expected vs. actual behavior
Expected ChordReducer.run(score) to complete without error; instead, raises TypeError at music21/tree/timespanTree.py, line 743, in TimespanTree.allParts().

More information
ChordReducer.run() calls TimespanTree.allParts() internally, which returns a list of the tree's parts. This list is ordered by the partId of each part's first instrument, using the following sort:

parts = sorted(parts, key=lambda x: x.getInstrument().partId) 

x.getInstrument() returns the first available instrument in the part, or a new default instrument. In either case, the partId could be None.

One possible fix for the NoneType comparison: having allParts() utilize the input source's ordering to sort the parts. The ordering is available for at least this use case, since ChordReducer.run() already validates that its input is a stream.Score, and the TimespanTree that it uses already keeps track of the source in its source attribute. For just the stream.Score case, allParts() could then return the parts in order of their appearance in the score. Or, more generally, for a solution that works with other stream types that TimespanTree can process, allParts() could always return the list of parts ordered using the source's ordering.

Applying chordify() to the input score beforehand (stream.Score([score.chordify()])), avoids the TypeError being raised, although the chordified score contains just one part.

Lingua principale
Python
Stelle
2.6k
Fork
459
Merge medio
1g 7h
PR unite (30g)
40

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cuthbertLab/music21

Tutte le issue di cuthbertLab/music21

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.