From 598557a602ab0c6042c0a364e64fd6df04b6754c Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Thu, 13 Jun 2024 14:02:52 -1000 Subject: [PATCH] fix newly discovered lint errors --- .pylintrc | 1 + music21/figuredBass/resolution.py | 45 +++++++++++++++++++++++-------- music21/stream/base.py | 4 +-- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/.pylintrc b/.pylintrc index e1e3a5c85..d823a13bc 100644 --- a/.pylintrc +++ b/.pylintrc @@ -101,6 +101,7 @@ disable= unnecessary-lambda-assignment, # opinionated consider-using-generator, # generators are less performant for small container sizes, like most of ours not-an-iterable, # false positives on RecursiveIterator in recent pylint versions. + unpacking-non-sequence, # also getting false positives. # 'protected-access', # this is an important one, but for now we do a lot of # # x = copy.deepcopy(self); x._volume = ... which is not a problem... diff --git a/music21/figuredBass/resolution.py b/music21/figuredBass/resolution.py index 64dd8ce90..90a287f7f 100644 --- a/music21/figuredBass/resolution.py +++ b/music21/figuredBass/resolution.py @@ -8,10 +8,8 @@ # License: BSD, see license.txt # ------------------------------------------------------------------------------ ''' -.. note:: The terminology, V43, viio, iv, etc. are explained - more fully in *The Music Theory Handbook* - by Marjorie Merryman. - +.. note:: The terminology, V43, viio, iv, etc. are explained elsewhere, + such as *The Music Theory Handbook* by Marjorie Merryman. This module contains methods which can properly resolve `dominant seventh `_, @@ -26,6 +24,7 @@ ''' from __future__ import annotations +import typing as t import unittest from music21 import exceptions21 @@ -35,12 +34,15 @@ from music21 import stream -def augmentedSixthToDominant(augSixthPossib, augSixthType=None, augSixthChordInfo=None): +def augmentedSixthToDominant( + augSixthPossib, + augSixthType: int | None = None, + augSixthChordInfo: list[pitch.Pitch, None] | None = None +) -> tuple[pitch.Pitch, ...]: ''' Resolves French (augSixthType = 1), German (augSixthType = 2), and Swiss (augSixthType = 3) augmented sixth chords to the root position dominant triad. - Proper Italian augmented sixth resolutions not supported within this method. >>> from music21.figuredBass import resolution @@ -97,10 +99,14 @@ def augmentedSixthToDominant(augSixthPossib, augSixthType=None, augSixthChordInf elif augSixthChord.isSwissAugmentedSixth(): augSixthType = 3 + if t.TYPE_CHECKING: + assert augSixthChordInfo is not None if augSixthType in (1, 3): [bass, other, root, unused_third, fifth] = augSixthChordInfo # other == sixth elif augSixthType == 2: [bass, root, unused_third, fifth, other] = augSixthChordInfo # other == seventh + else: + raise ResolutionException(f'Unknown augSixthType: {augSixthType|r}') howToResolve = [(lambda p: p.name == bass.name, '-m2'), (lambda p: p.name == root.name, 'm2'), @@ -111,7 +117,11 @@ def augmentedSixthToDominant(augSixthPossib, augSixthType=None, augSixthChordInf return _resolvePitches(augSixthPossib, howToResolve) -def augmentedSixthToMajorTonic(augSixthPossib, augSixthType=None, augSixthChordInfo=None): +def augmentedSixthToMajorTonic( + augSixthPossib, + augSixthType: int | None = None, + augSixthChordInfo: list[pitch.Pitch, None] | None = None +) -> tuple[pitch.Pitch, ...]: ''' Resolves French (augSixthType = 1), German (augSixthType = 2), and Swiss (augSixthType = 3) augmented sixth chords to the major tonic 6,4. @@ -167,10 +177,15 @@ def augmentedSixthToMajorTonic(augSixthPossib, augSixthType=None, augSixthChordI elif augSixthChord.isSwissAugmentedSixth(): augSixthType = 3 + if t.TYPE_CHECKING: + assert augSixthChordInfo is not None + if augSixthType in (1, 3): [bass, other, root, unused_third, fifth] = augSixthChordInfo # other == sixth elif augSixthType == 2: [bass, root, unused_third, fifth, other] = augSixthChordInfo # other == seventh + else: + raise ResolutionException(f'Unknown augSixthType: {augSixthType|r}') howToResolve = [(lambda p: p.name == bass.name, '-m2'), (lambda p: p.name == root.name, 'm2'), @@ -182,12 +197,15 @@ def augmentedSixthToMajorTonic(augSixthPossib, augSixthType=None, augSixthChordI return _resolvePitches(augSixthPossib, howToResolve) -def augmentedSixthToMinorTonic(augSixthPossib, augSixthType=None, augSixthChordInfo=None): +def augmentedSixthToMinorTonic( + augSixthPossib, + augSixthType: int | None = None, + augSixthChordInfo: list[pitch.Pitch, None] | None = None +) -> tuple[pitch.Pitch, ...]: ''' Resolves French (augSixthType = 1), German (augSixthType = 2), and Swiss (augSixthType = 3) augmented sixth chords to the minor tonic 6,4. - Proper Italian augmented sixth resolutions not supported within this method. >>> from music21.figuredBass import resolution @@ -238,10 +256,15 @@ def augmentedSixthToMinorTonic(augSixthPossib, augSixthType=None, augSixthChordI elif augSixthChord.isSwissAugmentedSixth(): augSixthType = 3 + if t.TYPE_CHECKING: + assert augSixthChordInfo is not None + if augSixthType in (1, 3): [bass, other, root, unused_third, fifth] = augSixthChordInfo # other == sixth elif augSixthType == 2: [bass, root, unused_third, fifth, other] = augSixthChordInfo # other == seventh + else: + raise ResolutionException(f'Unknown augSixthType: {augSixthType|r}') howToResolve = [(lambda p: p.name == bass.name, '-m2'), (lambda p: p.name == root.name, 'm2'), @@ -727,14 +750,14 @@ def _transpose(samplePitch, intervalString): return samplePitch.transpose(intervalString) -def _resolvePitches(possibToResolve, howToResolve): +def _resolvePitches(possibToResolve, howToResolve) -> tuple[pitch.Pitch, ...]: ''' Takes in a possibility to resolve and a list of (lambda function, intervalString) pairs and transposes each pitch by the intervalString corresponding to the lambda function that returns True when applied to the pitch. ''' howToResolve.append((lambda p: True, 'P1')) - resPitches = [] + resPitches: list[pitch.Pitch] = [] for samplePitch in possibToResolve: for (expression, intervalString) in howToResolve: if expression(samplePitch): diff --git a/music21/stream/base.py b/music21/stream/base.py index e407600f6..0d0db5fc9 100644 --- a/music21/stream/base.py +++ b/music21/stream/base.py @@ -4137,7 +4137,7 @@ def getElementAtOrBefore( # TODO: allow sortTuple as a parameter (in all getElement...) candidates = [] - offset = opFrac(offset) + offset: OffsetQL = opFrac(offset) nearestTrailSpan = offset # start with max time sIterator = self.iter() @@ -4147,7 +4147,7 @@ def getElementAtOrBefore( # need both _elements and _endElements for e in sIterator: - span = opFrac(offset - self.elementOffset(e)) + span: OffsetQL = opFrac(offset - self.elementOffset(e)) # environLocal.printDebug(['e span check', span, 'offset', offset, # 'e.offset', e.offset, 'self.elementOffset(e)', self.elementOffset(e), 'e', e]) if span < 0 or (span == 0 and _beforeNotAt):