Skip to content

Commit 024e4d7

Browse files
authored
Merge pull request #2102 from cuthbertLab/chord-empty-bool
Document that an empty Chord is False
2 parents b2d824c + ca5eee6 commit 024e4d7

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎music21/chord/__init__.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,31 @@ class Chord(ChordBase):
725725
False
726726
>>> c1 != c2
727727
True
728+
729+
**Empty chords**
730+
731+
A chord with no pitches is False, so `if not c:` finds one:
732+
733+
>>> emptyChord = chord.Chord()
734+
>>> len(emptyChord)
735+
0
736+
>>> bool(emptyChord)
737+
False
738+
>>> bool(c1)
739+
True
740+
741+
Most methods still answer:
742+
743+
>>> emptyChord.commonName
744+
'empty chord'
745+
>>> emptyChord.quality
746+
'other'
747+
748+
But calling `root()` on an empty chord raises an exception:
749+
750+
>>> emptyChord.root()
751+
Traceback (most recent call last):
752+
music21.chord.ChordException: no pitches in chord <music21.chord.Chord ...>
728753
'''
729754
# CLASS VARIABLES #
730755
isChord = True

0 commit comments

Comments
 (0)