From 9e2b17a6b9f48bfeefe752b21afd97d1d5f5353c Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Wed, 3 Nov 2021 21:05:45 +0100 Subject: [PATCH] Issue #85: Convert 12 statements to the usage of augmented assignments Augmented assignment statements became available with Python 2. https://docs.python.org/3/whatsnew/2.0.html#augmented-assignment Thus improve 12 source code places accordingly. Signed-off-by: Markus Elfring --- mingus/core/chords.py | 4 ++-- mingus/core/intervals.py | 4 ++-- mingus/core/progressions.py | 2 +- mingus/extra/fft.py | 4 ++-- mingus/midi/midi_track.py | 2 +- mingus_examples/pygame-piano/pygame-piano.py | 4 ++-- scripts/api_doc_generator.py | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mingus/core/chords.py b/mingus/core/chords.py index 62d6fbf5..5f204574 100644 --- a/mingus/core/chords.py +++ b/mingus/core/chords.py @@ -1051,7 +1051,7 @@ def add_result(short, poly=False): # Recognizing polychords if tries == 1 and not no_polychords: - polychords = polychords + determine_polychords(seventh, shorthand) + polychords += determine_polychords(seventh, shorthand) # Recognizing sevenths for triad in triads: @@ -1333,7 +1333,7 @@ def determine_polychords(chord, shorthand=False): polychords.append("%s|%s" % (chord1, chord2)) if shorthand: for p in polychords: - p = p + " polychord" + p += " polychord" return polychords diff --git a/mingus/core/intervals.py b/mingus/core/intervals.py index 41920969..35b8ad06 100644 --- a/mingus/core/intervals.py +++ b/mingus/core/intervals.py @@ -292,10 +292,10 @@ def augment_or_diminish_until_the_interval_is_right(note1, note2, interval): # These are some checks to see if we have generated too much #'s or too much # b's. In these cases we need to convert #'s to b's and vice versa. if val > 6: - val = val % 12 + val %= 12 val = -12 + val elif val < -6: - val = val % -12 + val %= -12 val = 12 + val # Rebuild the note diff --git a/mingus/core/progressions.py b/mingus/core/progressions.py index b1137550..8ab9d8fc 100644 --- a/mingus/core/progressions.py +++ b/mingus/core/progressions.py @@ -245,7 +245,7 @@ def tuple_to_string(prog_tuple): if acc > 6: acc = 0 - acc % 6 elif acc < -6: - acc = acc % 6 + acc %= 6 while acc < 0: roman = "b" + roman acc += 1 diff --git a/mingus/extra/fft.py b/mingus/extra/fft.py index 5e785424..ed024460 100644 --- a/mingus/extra/fft.py +++ b/mingus/extra/fft.py @@ -102,9 +102,9 @@ def find_frequencies(data, freq=44100, bits=16): # Scale by the length (n) and square the value to get the amplitude p = [(abs(x) / float(n)) ** 2 * 2 for x in p[0:uniquePts]] - p[0] = p[0] / 2 + p[0] /= 2 if n % 2 == 0: - p[-1] = p[-1] / 2 + p[-1] /= 2 # Generate the frequencies and zip with the amplitudes s = freq / float(n) diff --git a/mingus/midi/midi_track.py b/mingus/midi/midi_track.py index f3fa6900..6d8392c2 100644 --- a/mingus/midi/midi_track.py +++ b/mingus/midi/midi_track.py @@ -281,5 +281,5 @@ def int_to_varbyte(self, value): # Set the first bit on every one but the last bit. for i in range(len(bytes) - 1): - bytes[i] = bytes[i] | 0x80 + bytes[i] |= 0x80 return pack("%sB" % len(bytes), *bytes) diff --git a/mingus_examples/pygame-piano/pygame-piano.py b/mingus_examples/pygame-piano/pygame-piano.py index d4019d36..1538ffab 100755 --- a/mingus_examples/pygame-piano/pygame-piano.py +++ b/mingus_examples/pygame-piano/pygame-piano.py @@ -124,7 +124,7 @@ def play_note(note): # Getting the x coordinate of a white key can be done automatically w = WHITE_KEYS.index(note.name) * white_key_width - w = w + octave_offset + w += octave_offset # Add a list containing the x coordinate, the tick at the current time # and of course the note itself to playing_w @@ -145,7 +145,7 @@ def play_note(note): w = 151 else: w = 187 - w = w + octave_offset + w += octave_offset playing_b.append([w, tick, note]) # To find out what sort of chord is being played we have to look at both the diff --git a/scripts/api_doc_generator.py b/scripts/api_doc_generator.py index e02b350d..248e97ee 100755 --- a/scripts/api_doc_generator.py +++ b/scripts/api_doc_generator.py @@ -157,11 +157,11 @@ def generate_callable_wikidocs(self, module_string, element_string, evaled, is_c self.classes.append(docs) elif _is_class(type(evaled)): self.classes.append('\n.. class:: ' + element_string + '\n\n') - module_string = module_string + "." + element_string + module_string += "." + element_string self.process_element_recursively(module_string, evaled, True) elif hasattr(evaled, '__module__') and evaled.__module__ is not None and evaled.__module__.startswith(module_string): self.classes.append('\n.. class:: ' + element_string + '\n\n') - module_string = module_string + "." + element_string + module_string += "." + element_string self.process_element_recursively(module_string, evaled, True) else: pass