Skip to content

Commit

Permalink
fix newly discovered lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Jun 14, 2024
1 parent 4df9575 commit 598557a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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...

Expand Down
45 changes: 34 additions & 11 deletions music21/figuredBass/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://en.wikipedia.org/wiki/Dominant_seventh_chord>`_,
Expand All @@ -26,6 +24,7 @@
'''
from __future__ import annotations

import typing as t
import unittest

from music21 import exceptions21
Expand All @@ -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
Expand Down Expand Up @@ -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'),
Expand All @@ -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.
Expand Down Expand Up @@ -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'),
Expand All @@ -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
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions music21/stream/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down

0 comments on commit 598557a

Please sign in to comment.