Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#2,074 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
data

Hướng nghiên cứu

Lỗi crash nằm ở TimespanTree.allParts() trong music21/tree/timespanTree.py (khoảng dòng 743), nơi các phần được sắp xếp theo getInstrument().partId, giá trị này có thể là None. Hãy bắt đầu từ ChordReducer.run() trong music21/analysis/reduceChords.py và chạy script tái hiện trong issue. Việc hoàn thành được xác định khi script chạy xong không có TypeError và các phần giữ được thứ tự hợp lý, ví dụ thứ tự chúng xuất hiện trong bản nhạc. Issue đề xuất hai cách sắp xếp, vì vậy hãy hỏi các maintainer xem nên dùng cách nào.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
2.6k
Fork
459
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
40

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cuthbertLab/music21

Tất cả issue của cuthbertLab/music21

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.