Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#2,074 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
data

調査の方向性

クラッシュは music21/tree/timespanTree.py の(743行目付近の)TimespanTree.allParts() で発生しています。ここではパートを getInstrument().partId でソートしており、その値は None になることがあります。music21/analysis/reduceChords.py の ChordReducer.run() から始めて、Issue にある再現スクリプトを実行してください。完了の条件は、スクリプトが TypeError なしで終了し、パートがスコア内に現れる順序など妥当な順序を保つことです。Issue では並び順が2通り提案されているので、どちらを使うかはメンテナーに確認してください。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
2.6k
フォーク
459
平均マージ
1日 7時間
マージ済み PR(30日)
40

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cuthbertLab/music21 のほかの issue

cuthbertLab/music21 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。