From 3f9880c50e2491fd2d9a3b6c107d4d557f49e7e8 Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Tue, 2 Apr 2024 13:07:48 -1000 Subject: [PATCH] fix chords and lint --- music21/tree/verticality.py | 48 ++++++++++++++++++++----------------- music21/voiceLeading.py | 12 ++++++---- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/music21/tree/verticality.py b/music21/tree/verticality.py index cc77c8447..27d43773d 100644 --- a/music21/tree/verticality.py +++ b/music21/tree/verticality.py @@ -210,19 +210,19 @@ class Verticality(prebase.ProtoM21Object): def __init__( self, - offset: OffsetQL | None = None, - overlapTimespans=(), - startTimespans=(), - stopTimespans=(), + offset: OffsetQL = 0.0, + overlapTimespans: tuple[spans.ElementTimespan, ...] =(), + startTimespans: tuple[spans.ElementTimespan, ...] =(), + stopTimespans: tuple[spans.ElementTimespan, ...] =(), timespanTree=None, ): - from music21.tree import trees - if timespanTree is not None and not isinstance(timespanTree, trees.OffsetTree): + from music21.tree.timespanTree import TimespanTree + if timespanTree is not None and not isinstance(timespanTree, TimespanTree): raise VerticalityException( - f'timespanTree {timespanTree!r} is not a OffsetTree or None') + f'timespanTree {timespanTree!r} is not a TimespanTree or None') - self.timespanTree: trees.OffsetTree | None = timespanTree - self.offset: OffsetQL | None = offset + self.timespanTree: TimespanTree | None = timespanTree + self.offset: OffsetQL = offset if not isinstance(startTimespans, tuple): raise VerticalityException( @@ -753,6 +753,9 @@ def makeElement( else: quarterLength = common.opFrac(quarterLength) + if t.TYPE_CHECKING: + assert quarterLength is not None + if not self.pitchSet: r = note.Rest() r.duration.quarterLength = quarterLength @@ -962,7 +965,7 @@ def getAllVoiceLeadingQuartets( includeRests=True, includeOblique=True, includeNoMotion=False, - returnObjects: bool = True, + returnObjects: t.Literal[True] = True, partPairNumbers: list[tuple[int, int]] | None = None ) -> list[VoiceLeadingQuartet]: # dummy until Astroid #1015 is fixed. Replace with ... @@ -985,7 +988,7 @@ def getAllVoiceLeadingQuartets( ... classList=(note.Note, chord.Chord)) >>> verticality22 = tsCol.getVerticalityAt(22.0) - >>> from pprint import pprint + >>> from pprint import pprint as pp >>> for vlq in verticality22.getAllVoiceLeadingQuartets(): ... pp(vlq) Generator[VoiceLeadingQuartet, None, None]: ''' Iterate through all VoiceLeading quartets in a Stream (generally a Score), - yielding a generator of quartets + yielding a generator of VoiceLeadingQuartets. N.B. does not yet support Streams with + Chords in them. >>> b = corpus.parse('bwv66.6') >>> for vlq in voiceLeading.iterateAllVoiceLeadingQuartets(b): @@ -2438,10 +2439,11 @@ def iterateAllVoiceLeadingQuartets( ... ''' for v in s.asTimespans().iterateVerticalities(reverse=reverse): - for vlq in v.getAllVoiceLeadingQuartets( - includeRests=includeRests, includeOblique=includeOblique, includeNoMotion=includeNoMotion - ): - yield vlq + yield from v.getAllVoiceLeadingQuartets( + includeRests=includeRests, + includeOblique=includeOblique, + includeNoMotion=includeNoMotion + ) # ------------------------------------------------------------------------------