Skip to content

Commit

Permalink
Merge pull request #1282 from cuthbertLab/typing-iterator
Browse files Browse the repository at this point in the history
add typing to iterators
  • Loading branch information
mscuthbert authored Apr 27, 2022
2 parents fcb97b4 + d32567b commit d7ec854
Show file tree
Hide file tree
Showing 73 changed files with 1,228 additions and 1,038 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ confidence=
# anything changed here, also change in test/testLint.py for now

disable=
not-an-iterable, # TOO BAD -- this is important, but so many false positives
cyclic-import, # we use these inside functions when there's a deep problem.
unnecessary-pass, # not really a problem..
locally-disabled, # test for this later, but hopefully will know what we're doing
Expand Down
2 changes: 0 additions & 2 deletions documentation/docbuild/documenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,7 @@ def readonlyProperties(self):
<docbuild.documenters.AttributeDocumenter: music21.stream.Stream.semiFlat>
<docbuild.documenters.AttributeDocumenter: music21.stream.Stream.sorted>
<docbuild.documenters.AttributeDocumenter: music21.stream.Stream.spanners>
<docbuild.documenters.AttributeDocumenter: music21.stream.Stream.variants>
<docbuild.documenters.AttributeDocumenter: music21.stream.Stream.voices>
'''
return self._readonlyProperties

Expand Down
8 changes: 4 additions & 4 deletions music21/abcFormat/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def abcToStreamPart(abcHandler, inputM21=None, spannerBundle=None):
# following the meta data, or in the open stream
if not clefSet and not p.recurse().getElementsByClass('Clef'):
if useMeasures: # assume at start of measures
p.getElementsByClass('Measure').first().clef = clef.bestClef(p, recurse=True)
p.getElementsByClass(stream.Measure).first().clef = clef.bestClef(p, recurse=True)
else:
p.insert(0, clef.bestClef(p, recurse=True))

Expand Down Expand Up @@ -725,7 +725,7 @@ def testAnacrusisPadding(self):
ah = abcFormat.ABCHandler()
ah.process(testFiles.hectorTheHero)
s = abcToStreamScore(ah)
m1 = s.parts[0].getElementsByClass('Measure').first()
m1 = s.parts[0].getElementsByClass(stream.Measure).first()
# s.show()
# ts is 3/4
self.assertEqual(m1.barDuration.quarterLength, 3.0)
Expand All @@ -750,7 +750,7 @@ def testAnacrusisPadding(self):
ah = abcFormat.ABCHandler()
ah.process(testFiles.theAleWifesDaughter)
s = abcToStreamScore(ah)
m1 = s.parts[0].getElementsByClass('Measure').first()
m1 = s.parts[0].getElementsByClass(stream.Measure).first()

# ts is 3/4
self.assertEqual(m1.barDuration.quarterLength, 4.0)
Expand Down Expand Up @@ -957,7 +957,7 @@ def testRepeatBracketsA(self):
# new problem case:
s = converter.parse(testFiles.hectorTheHero)
# first measure has 2 pickup notes
self.assertEqual(len(s.parts.first().getElementsByClass('Measure').first().notes), 2)
self.assertEqual(len(s.parts.first().getElementsByClass(stream.Measure).first().notes), 2)

def testRepeatBracketsB(self):
from music21.abcFormat import testFiles
Expand Down
4 changes: 2 additions & 2 deletions music21/analysis/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,10 @@ def getPitchSpan(self, subStream) -> Optional[Tuple[pitch.Pitch, pitch.Pitch]]:
>>> s = corpus.parse('bach/bwv66.6')
>>> p = analysis.discrete.Ambitus()
>>> pitchMin, pitchMax = p.getPitchSpan(s.parts[0].getElementsByClass('Measure')[3])
>>> pitchMin, pitchMax = p.getPitchSpan(s.parts[0].getElementsByClass(stream.Measure)[3])
>>> pitchMin.ps, pitchMax.ps
(66.0, 71.0)
>>> p.getPitchSpan(s.parts[0].getElementsByClass('Measure')[6])
>>> p.getPitchSpan(s.parts[0].getElementsByClass(stream.Measure)[6])
(<music21.pitch.Pitch A4>, <music21.pitch.Pitch C#5>)
>>> s = stream.Stream()
Expand Down
4 changes: 3 additions & 1 deletion music21/analysis/floatingKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'''
import copy
from music21 import key
from music21 import stream
from music21.exceptions21 import AnalysisException

class FloatingKeyException(AnalysisException):
Expand Down Expand Up @@ -89,7 +90,8 @@ def __init__(self, s=None):
p = s.iter().parts.first()
else:
p = s
self.numMeasures = len(p.getElementsByClass('Measure')) # could be wrong for endings, etc.
# could be wrong for endings, etc.
self.numMeasures = len(p.getElementsByClass(stream.Measure))
if self.numMeasures == 0:
raise FloatingKeyException("Stream must have Measures inside it")

Expand Down
2 changes: 1 addition & 1 deletion music21/analysis/reduceChords.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def run(self,
templateStream=inputScore,
)
chordifiedPart = stream.Part()
for measure in chordifiedReduction.getElementsByClass('Measure'):
for measure in chordifiedReduction.getElementsByClass(stream.Measure):
reducedMeasure = self.reduceMeasureToNChords(
measure,
maximumNumberOfChords=maximumNumberOfChords,
Expand Down
13 changes: 7 additions & 6 deletions music21/analysis/reduceChordsOld.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def multiPartReduction(self, inStream, maxChords=2, closedPosition=False, forceO
if not p0:
return p
self._lastPitchedObject = None
lenMeasures = len(p0.getElementsByClass('Measure'))
lenMeasures = len(p0.getElementsByClass(stream.Measure))
self._lastTs = None
for i in range(lenMeasures):
mI = inStream.measure(i, indicesNotNumbers=True)
Expand All @@ -257,7 +257,7 @@ def multiPartReduction(self, inStream, maxChords=2, closedPosition=False, forceO
if i % 20 == 0 and i != 0:
print("")
p.coreElementsChanged()
m = p.getElementsByClass('Measure').first()
m = p.getElementsByClass(stream.Measure).first()
if m:
m.insert(0, clef.bestClef(p, allowTreble8vb=True))
p.makeNotation(inPlace=True)
Expand Down Expand Up @@ -318,7 +318,7 @@ def reduceThisMeasure(self, mI, measureIndex, maxChords, closedPosition, forceOc
self._lastPitchedObject.tie = tie.Tie('start')
self._lastPitchedObject = m[-1]

sourceMeasureTs = mI.parts.first().getElementsByClass('Measure').first().timeSignature
sourceMeasureTs = mI.parts.first().getElementsByClass(stream.Measure).first().timeSignature
if sourceMeasureTs != self._lastTs:
m.timeSignature = copy.deepcopy(sourceMeasureTs)
self._lastTs = sourceMeasureTs
Expand Down Expand Up @@ -354,11 +354,12 @@ def testTrecentoMadrigal(self):
# fix clef
fixClef = True
if fixClef:
startClefs = c.parts[1].getElementsByClass('Measure').first().getElementsByClass('Clef')
startClefs = c.parts[1].getElementsByClass(stream.Measure
).first().getElementsByClass('Clef')
if startClefs:
clef1 = startClefs[0]
c.parts[1].getElementsByClass('Measure').first().remove(clef1)
c.parts[1].getElementsByClass('Measure').first().insert(0, clef.Treble8vbClef())
c.parts[1].getElementsByClass(stream.Measure).first().remove(clef1)
c.parts[1].getElementsByClass(stream.Measure).first().insert(0, clef.Treble8vbClef())


cr = ChordReducer()
Expand Down
12 changes: 6 additions & 6 deletions music21/analysis/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _extractReductionEvents(self, score, removeAfterParsing=True):
return
# iterate overall notes, check all lyrics
for p in score.parts:
for i, m in enumerate(p.getElementsByClass('Measure')):
for i, m in enumerate(p.getElementsByClass(stream.Measure)):
for n in m.recurse().notes:
infoDict = {'part': p,
'measure': m,
Expand Down Expand Up @@ -358,7 +358,7 @@ def _createReduction(self):
inst = instrument.Instrument()
inst.partName = gName
g.insert(0, inst)
gMeasures = g.getElementsByClass('Measure')
gMeasures = g.getElementsByClass(stream.Measure)
# for m in gMeasures._elements:
# print(gName, m)
# m.clef = clef.TrebleClef()
Expand Down Expand Up @@ -392,7 +392,7 @@ def _createReduction(self):
gMeasure.insert(rn.measureOffset, te)

# after gathering all parts, fill with rests
for i, m in enumerate(g.getElementsByClass('Measure')):
for i, m in enumerate(g.getElementsByClass(stream.Measure)):
# only make rests if there are notes in the measure
for v in m.voices:
if v.recurse().notes:
Expand Down Expand Up @@ -576,7 +576,7 @@ def _createEventSpans(self):
if self._fillByMeasure:
partMeasures = []
for p in parts:
partMeasures.append(p.getElementsByClass('Measure').stream())
partMeasures.append(p.getElementsByClass(stream.Measure).stream())
# environLocal.printDebug(['partMeasures', partMeasures])
# assuming that all parts have same number of measures
# iterate over each measures
Expand Down Expand Up @@ -963,11 +963,11 @@ def testExtractionB(self):
# import warnings
# with warnings.catch_warnings(): # catch deprecation warning
# warnings.simplefilter('ignore', category=exceptions21.Music21DeprecationWarning)
# chords = src.flattenParts().makeChords(minimumWindowSize=4,
# chords = src.flatten().makeChords(minimumWindowSize=4, # make chords is gone
# makeRests=False)
# for c in chords.flatten().notes:
# c.quarterLength = 4
# for m in chords.getElementsByClass('Measure'):
# for m in chords.getElementsByClass(stream.Measure):
# m.clef = clef.bestClef(m, recurse=True)
#
# chords.measure(1).notes[0].addLyric('::/p:e/o:5/nf:no/ta:3/g:Ursatz')
Expand Down
8 changes: 4 additions & 4 deletions music21/analysis/windowed.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ def getMinimumWindowStream(self, timeSignature='1/4'):
>>> wa = analysis.windowed.WindowedAnalysis(s.parts[0], p)
>>> post = wa.getMinimumWindowStream()
>>> len(post.getElementsByClass('Measure'))
>>> len(post.getElementsByClass(stream.Measure))
42
>>> post.getElementsByClass('Measure').first()
>>> post.getElementsByClass(stream.Measure).first()
<music21.stream.Measure 1 offset=0.0>
Time signature set to 1/4 time signature
>>> post.getElementsByClass('Measure').first().timeSignature
>>> post.getElementsByClass(stream.Measure).first().timeSignature
<music21.meter.TimeSignature 1/4>
leaves one note in this measure
>>> len(post.getElementsByClass('Measure')[1].notes)
>>> len(post.getElementsByClass(stream.Measure)[1].notes)
1
Placing a score with parts into analysis will automatically flatten
Expand Down
2 changes: 1 addition & 1 deletion music21/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def direction(self, value: str):
@property
def times(self) -> Optional[int]:
'''
Get or set the times property of this barline. This
Get or set the "times" property of this barline. This
defines how many times the repeat happens. A standard repeat
repeats 2 times; values equal to or greater than 0 are permitted.
A repeat of 0 skips the repeated passage.
Expand Down
Loading

0 comments on commit d7ec854

Please sign in to comment.