Skip to content

Commit dbd8c9f

Browse files
Fix pylint recommendations (#1694)
Pylint now recommends using `yield from` and the use of `min/max` to simplify if statements.
1 parent f2f7bad commit dbd8c9f

File tree

18 files changed

+43
-93
lines changed

18 files changed

+43
-93
lines changed

music21/analysis/reduceChords.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ def procedure(timespan):
384384
)
385385
print(msg)
386386
# raise ChordReducerException(msg)
387-
if offset < previousTimespan.endTime:
388-
offset = previousTimespan.endTime
387+
offset = max(offset, previousTimespan.endTime)
389388
scoreTree.removeTimespan(group[0])
390389
subtree.removeTimespan(group[0])
391390
newTimespan = group[0].new(offset=offset)
@@ -542,8 +541,7 @@ def reduceMeasureToNChords(
542541
measureObject.flatten().notes,
543542
weightAlgorithm,
544543
)
545-
if maximumNumberOfChords > len(chordWeights):
546-
maximumNumberOfChords = len(chordWeights)
544+
maximumNumberOfChords = min(maximumNumberOfChords, len(chordWeights))
547545
sortedChordWeights = sorted(
548546
chordWeights,
549547
key=chordWeights.get,

music21/analysis/reduceChordsOld.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ def reduceMeasureToNChords(self,
8686

8787
chordWeights = self.computeMeasureChordWeights(mObj, weightAlgorithm)
8888

89-
if numChords > len(chordWeights):
90-
numChords = len(chordWeights)
89+
numChords = min(numChords, len(chordWeights))
9190

9291
maxNChords = sorted(chordWeights, key=chordWeights.get, reverse=True)[:numChords]
9392
if not maxNChords:

music21/analysis/windowed.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,8 @@ def analyze(self, windowSize, windowType='overlap'):
193193
elif windowType == 'noOverlap':
194194
start = 0
195195
end = start + windowSize
196-
i = 0
197-
while True:
198-
if end >= len(self._windowedStream):
199-
end = len(self._windowedStream)
196+
for i in range(windowCount):
197+
end = min(end, len(self._windowedStream))
200198

201199
current = stream.Stream()
202200
for j in range(start, end):
@@ -210,9 +208,6 @@ def analyze(self, windowSize, windowType='overlap'):
210208

211209
start = end
212210
end = start + windowSize
213-
i += 1
214-
if i >= windowCount:
215-
break
216211

217212
elif windowType == 'adjacentAverage':
218213
# first get overlapping windows

music21/braille/text.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ def recenterHeadings(self):
336336
if self.allLines[i].isHeading:
337337
break
338338
lineLength = self.allLines[i].textLocation
339-
if lineLength > maxLineLength:
340-
maxLineLength = lineLength
339+
maxLineLength = max(maxLineLength, lineLength)
341340
for j in range(indexStart, indexFinal):
342341
brailleTextLine = self.allLines[j]
343342
lineStrToCenter = str(brailleTextLine)
@@ -565,12 +564,10 @@ def insert(self, textLocation, text):
565564
'''
566565
if not self.canInsert(textLocation, text):
567566
raise BrailleTextException('Text cannot be inserted at specified location.')
568-
self.textLocation = textLocation
569-
for char in list(text):
570-
self.allChars[self.textLocation] = char
571-
self.textLocation += 1
572-
if self.textLocation > self.highestUsedLocation:
573-
self.highestUsedLocation = self.textLocation
567+
for i, char in enumerate(text, start=textLocation):
568+
self.allChars[i] = char
569+
self.textLocation = textLocation + len(text)
570+
self.highestUsedLocation = max(self.highestUsedLocation, self.textLocation)
574571

575572
def canAppend(self, text, addSpace=True):
576573
'''
@@ -600,10 +597,7 @@ def canAppend(self, text, addSpace=True):
600597
>>> btl.canAppend('1234', addSpace=False)
601598
False
602599
'''
603-
if self.highestUsedLocation > self.textLocation:
604-
searchLocation = self.highestUsedLocation
605-
else:
606-
searchLocation = self.textLocation
600+
searchLocation = max(self.highestUsedLocation, self.textLocation)
607601
addSpaceAmount = 1 if addSpace else 0
608602
if (searchLocation + len(text) + addSpaceAmount) > self.lineLength:
609603
return False

music21/common/objects.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ class RelativeCounter(collections.Counter):
6767

6868
def __iter__(self):
6969
sortedKeys = sorted(super().__iter__(), key=lambda x: self[x], reverse=True)
70-
for k in sortedKeys:
71-
yield k
70+
yield from sortedKeys
7271

7372
def items(self):
7473
for k in self:

music21/features/jSymbolic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,8 +3016,7 @@ def process(self):
30163016
for p in c.pitches:
30173017
for gSub in p.groups:
30183018
g.append(gSub) # add to temporary group; will act as a set
3019-
if len(g) > found:
3020-
found = len(g)
3019+
found = max(found, len(g))
30213020
self.feature.vector[0] = found
30223021

30233022

music21/figuredBass/realizer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@ def addLyricsToBassNote(bassNote, notationString=None):
186186
n = notation.Notation(notationString)
187187
if not n.figureStrings:
188188
return
189-
maxLength = 0
190-
for fs in n.figureStrings:
191-
if len(fs) > maxLength:
192-
maxLength = len(fs)
189+
maxLength = max([len(fs) for fs in n.figureStrings])
193190
for fs in n.figureStrings:
194191
spacesInFront = ''
195192
for i in range(maxLength - len(fs)):

music21/humdrum/spineParser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ def parseEventListFromDataStream(self, dataStream=None):
401401
self.eventList.append(GlobalCommentLine(self.parsePositionInStream, line))
402402
else:
403403
thisLine = SpineLine(self.parsePositionInStream, line)
404-
if thisLine.numSpines > self.maxSpines:
405-
self.maxSpines = thisLine.numSpines
404+
self.maxSpines = max(self.maxSpines, thisLine.numSpines)
406405
self.eventList.append(thisLine)
407406
self.parsePositionInStream += 1
408407
self.fileLength = self.parsePositionInStream

music21/musicxml/m21ToXml.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,8 +1551,7 @@ def setPartsAndRefStream(self) -> None:
15511551
else:
15521552
innerStream.transferOffsetToElements()
15531553
ht = innerStream.highestTime
1554-
if ht > self.highestTime:
1555-
self.highestTime = ht
1554+
self.highestTime = max(self.highestTime, ht)
15561555
self.refStreamOrTimeRange = [0.0, self.highestTime]
15571556
self.parts = list(s.parts)
15581557

music21/musicxml/xmlToM21.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,8 +1967,7 @@ def xmlMeasureToMeasure(self, mxMeasure: ET.Element) -> stream.Measure:
19671967

19681968
self.lastMeasureParser = measureParser
19691969

1970-
if measureParser.staves > self.maxStaves:
1971-
self.maxStaves = measureParser.staves
1970+
self.maxStaves = max(self.maxStaves, measureParser.staves)
19721971

19731972
if measureParser.transposition is not None:
19741973
self.updateTransposition(measureParser.transposition)

0 commit comments

Comments
 (0)