From b92727d7475a47b8a2373f1f95701e28b39c3e5b Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Mon, 28 Oct 2024 17:02:07 -1000 Subject: [PATCH] typing, mypy, lost -> list --- dist/dist.py | 2 +- music21/musedata/__init__.py | 27 ++++++++++++++------------- music21/musedata/translate.py | 2 +- music21/repeat.py | 2 +- music21/scale/__init__.py | 2 +- music21/scale/test_intervalNetwork.py | 2 +- music21/stream/tests.py | 2 +- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/dist/dist.py b/dist/dist.py index 77ca57b4c..20d9c0615 100644 --- a/dist/dist.py +++ b/dist/dist.py @@ -14,7 +14,7 @@ To do a release, -1. update the VERSION in _version.py and the single test cases in base.py. +1. update the VERSION in _version.py and the single test case in base.py. 2. run `corpus.corpora.CoreCorpus().cacheMetadata()`. for a major change that affects parsing run corpus.corpora.CoreCorpus().rebuildMetadataCache() (20 min on IntelMacbook Air) -- either of these MAY change a diff --git a/music21/musedata/__init__.py b/music21/musedata/__init__.py index 69c75e7a7..f1b2b9ee6 100644 --- a/music21/musedata/__init__.py +++ b/music21/musedata/__init__.py @@ -74,7 +74,7 @@ def __init__( else: self.stage = None # store frequently used values - self._cache = {} + self._cache: dict[str, str|None] = {} def isRest(self) -> bool: ''' @@ -398,9 +398,9 @@ def getBeams(self): # TODO: need to get slurs from this indication: # (), {}, [] - def _getAdditionalNotations(self): + def _getAdditionalNotations(self) -> str|None: ''' - Return an articulation object or None + Return an articulation string or None >>> mdr = musedata.MuseDataRecord('C4 12 e u [ .p') >>> mdr._getAdditionalNotations() @@ -420,16 +420,17 @@ def _getAdditionalNotations(self): except KeyError: pass + data: str|None if len(self.src) < 31: data = None else: # accumulate chars 32-43, index 31, 42 - data = [] + data_list = [] i = 31 while i <= 42 and i < len(self.src): - data.append(self.src[i]) + data_list.append(self.src[i]) i += 1 - data = ''.join(data).strip() + data = ''.join(data_list).strip() self._cache['_getAdditionalNotations'] = data return data @@ -578,7 +579,7 @@ class MuseDataRecordIterator: ''' def __init__(self, src, parent): - self.src = src # the lost of all record lines + self.src = src # the list of all record lines self.index = 0 self.parent = parent @@ -738,7 +739,7 @@ class MuseDataMeasureIterator: ''' def __init__(self, src, boundaries, parent): - self.src = src # the lost of all record lines + self.src = src # the list of all record lines self.boundaries = boundaries # pairs of all boundaries self.index = 0 self.parent = parent @@ -1468,11 +1469,11 @@ class MuseDataFile(prebase.ProtoM21Object): When read, one or more MuseDataPart objects are created and stored on self.parts. ''' - def __init__(self): - self.parts = [] # a lost of MuseDataPart objects + def __init__(self) -> None: + self.parts: list[MuseDataPart] = [] - self.filename = None - self.file = None + self.filename: str|None = None + self.file: t.BinaryIO|None = None self.encoding: str = 'utf-8' def _reprInternal(self): @@ -1550,7 +1551,7 @@ class MuseDataWork(prebase.ProtoM21Object): A work might consist of one or more files. ''' - def __init__(self): + def __init__(self) -> None: self.files: list[MuseDataFile] = [] self.encoding: str = 'utf-8' diff --git a/music21/musedata/translate.py b/music21/musedata/translate.py index e0184451c..28b624078 100644 --- a/music21/musedata/translate.py +++ b/music21/musedata/translate.py @@ -94,7 +94,7 @@ def _musedataRecordListToNoteOrChord(records, previousElement=None): post.pitch = records[0].getPitchObject() else: # environLocal.printDebug(['attempting chord creation: records', len(records)]) - # can supply a lost of Pitch objects at creation + # can supply a list of Pitch objects at creation post = chord.Chord([r.getPitchObject() for r in records]) # if a chord, we are assuming that all durations are the same diff --git a/music21/repeat.py b/music21/repeat.py index 8843da337..903207ab6 100644 --- a/music21/repeat.py +++ b/music21/repeat.py @@ -93,7 +93,7 @@ def __init__(self, **keywords): super().__init__(**keywords) # store a text version of this expression self._textExpression = None - # store a lost of alternative text representations + # store a list of alternative text representations self._textAlternatives = [] # store a default text justification self.style.justify = 'center' diff --git a/music21/scale/__init__.py b/music21/scale/__init__.py index ad20ef311..0c7d0d61f 100644 --- a/music21/scale/__init__.py +++ b/music21/scale/__init__.py @@ -1537,7 +1537,7 @@ def tuneOnePitch(p, dst: list[pitch.Pitch]): for e in streamObj.recurse().notes: # get notes and chords if e.isChord: elementPitches = e.pitches - else: # simulate a lost + else: # simulate a list elementPitches = [e.pitch] # store a list of reset chord pitches diff --git a/music21/scale/test_intervalNetwork.py b/music21/scale/test_intervalNetwork.py index b9d4c11f8..6afac25d3 100644 --- a/music21/scale/test_intervalNetwork.py +++ b/music21/scale/test_intervalNetwork.py @@ -234,7 +234,7 @@ def testBasicA(self): '[(5, Terminus.HIGH), (Terminus.HIGH, 5)]' ) - # in calling get next, get a lost of edges and a lost of nodes that all + # in calling get next, get a list of edges and a list of nodes that all # describe possible pathways self.assertEqual( net.getNext(net.nodes[Terminus.LOW], Direction.ASCENDING), diff --git a/music21/stream/tests.py b/music21/stream/tests.py index adb263365..8c336783d 100644 --- a/music21/stream/tests.py +++ b/music21/stream/tests.py @@ -3768,7 +3768,7 @@ def procCompare(mf_inner, match_inner): n = note.Note('g#3') n.quarterLength = 0.5 s.repeatAppend(n, 6) - # post = s.midiTracks # get a lost + # post = s.midiTracks # a list post = midiTranslate.streamHierarchyToMidiTracks(s) self.assertEqual(len(post[1].events), 30)