From 93f3ad3f78d185e7c5e3e1c20817a8a8213f6d0d Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Sat, 27 Jul 2024 22:47:36 -1000 Subject: [PATCH 1/5] Pin Numpy to <2.0 Many changes in Numpy 2.0 -- fixing other changes in other dev systems. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d0e75c050f..8ec736d1d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,6 @@ joblib jsonpickle matplotlib more_itertools -numpy +numpy<2.0.0 webcolors>=1.5 requests From 87702e164bf55babb794352c7a01c9a633c05beb Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Sat, 27 Jul 2024 22:57:33 -1000 Subject: [PATCH 2/5] fix lint --- music21/braille/basic.py | 4 ++-- music21/derivation.py | 8 ++++---- music21/stream/base.py | 9 ++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/music21/braille/basic.py b/music21/braille/basic.py index 5904c04e47..32f976b07a 100644 --- a/music21/braille/basic.py +++ b/music21/braille/basic.py @@ -189,7 +189,7 @@ def chordToBraille(music21Chord, descending=True, showOctave=True): music21Chord.editorial.brailleEnglish.append(f'{music21Chord} None') return symbols['basic_exception'] chordTrans.append(brailleNote) - englishJoined = '\n'.join(initNote.editorial.brailleEnglish) + englishJoined = '\n'.join(initNote.editorial.get('brailleEnglish', [])) music21Chord.editorial.brailleEnglish.append( f'{direction} Chord:\n{englishJoined}' ) @@ -531,7 +531,7 @@ def metronomeMarkToBraille(music21MetronomeMark): metroNote = note.Note('C4', quarterLength=music21MetronomeMark.referent.quarterLength) brailleNote = noteToBraille(metroNote, showOctave=False) metroTrans.append(brailleNote) - englishJoined = ' '.join(metroNote.editorial.brailleEnglish) + englishJoined = ' '.join(metroNote.editorial.get(brailleEnglish, [])) music21MetronomeMark.editorial.brailleEnglish.append( f'Metronome Note {englishJoined}' ) diff --git a/music21/derivation.py b/music21/derivation.py index c9a4aa7b4b..ec3dfa695e 100644 --- a/music21/derivation.py +++ b/music21/derivation.py @@ -240,10 +240,10 @@ def chain(self) -> Generator[base.Music21Object, None, None]: >>> list(s3.derivation.chain()) == [s2, s1] True ''' - origin = self.origin - while origin is not None: - yield origin - origin = origin.derivation.origin + orig: Music21Object | None = self.origin + while orig is not None: + yield orig + orig = orig.derivation.origin @property def method(self) -> str|None: diff --git a/music21/stream/base.py b/music21/stream/base.py index 0d0db5fc97..87cdfcc4fe 100644 --- a/music21/stream/base.py +++ b/music21/stream/base.py @@ -7982,9 +7982,12 @@ def flatten(self: StreamType, retainContainers=False) -> StreamType: newId = str(sOldId) + '_' + method sNew.id = newId - sNew._derivation = derivation.Derivation(sNew) - sNew._derivation.origin = self - sNew.derivation.method = method + sNew_derivation = derivation.Derivation(sNew) + sNew_derivation.origin = self + sNew_derivation.method = method + + sNew.derivation = sNew_derivation + # storing .elements in here necessitates # create a new, independent cache instance in the flat representation sNew._cache = {} From a7058e5b0644802a17d1858cf79d588a450cdc94 Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Sat, 27 Jul 2024 23:09:00 -1000 Subject: [PATCH 3/5] fixing type-A errors --- music21/base.py | 2 +- music21/braille/basic.py | 2 +- music21/chord/__init__.py | 3 +- music21/derivation.py | 2 +- music21/meter/core.py | 1 - music21/stream/base.py | 2 +- music21/style.py | 68 +++++++++++++++++++-------------------- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/music21/base.py b/music21/base.py index a474d78f49..b85f2a9ac7 100644 --- a/music21/base.py +++ b/music21/base.py @@ -800,7 +800,7 @@ def style(self) -> Style: return self._style @style.setter - def style(self, newStyle: Style|None): + def style(self, newStyle: Style): self._style = newStyle # convenience. diff --git a/music21/braille/basic.py b/music21/braille/basic.py index 32f976b07a..fbc8e377bd 100644 --- a/music21/braille/basic.py +++ b/music21/braille/basic.py @@ -531,7 +531,7 @@ def metronomeMarkToBraille(music21MetronomeMark): metroNote = note.Note('C4', quarterLength=music21MetronomeMark.referent.quarterLength) brailleNote = noteToBraille(metroNote, showOctave=False) metroTrans.append(brailleNote) - englishJoined = ' '.join(metroNote.editorial.get(brailleEnglish, [])) + englishJoined = ' '.join(metroNote.editorial.get('brailleEnglish', [])) music21MetronomeMark.editorial.brailleEnglish.append( f'Metronome Note {englishJoined}' ) diff --git a/music21/chord/__init__.py b/music21/chord/__init__.py index 6a9145f50a..c3032f714f 100644 --- a/music21/chord/__init__.py +++ b/music21/chord/__init__.py @@ -4194,7 +4194,8 @@ def setColor(self, value, pitchTarget=None): ''' # assign to base if pitchTarget is None and self._notes: - self.style.color = value + chord_style = self.style + chord_style.color = value for n in self._notes: n.style.color = value diff --git a/music21/derivation.py b/music21/derivation.py index ec3dfa695e..223bf1695d 100644 --- a/music21/derivation.py +++ b/music21/derivation.py @@ -240,7 +240,7 @@ def chain(self) -> Generator[base.Music21Object, None, None]: >>> list(s3.derivation.chain()) == [s2, s1] True ''' - orig: Music21Object | None = self.origin + orig: base.Music21Object | None = self.origin while orig is not None: yield orig orig = orig.derivation.origin diff --git a/music21/meter/core.py b/music21/meter/core.py index 1b665dd580..5f62d534f1 100644 --- a/music21/meter/core.py +++ b/music21/meter/core.py @@ -1840,4 +1840,3 @@ def offsetToDepth(self, qLenPos, align='quantize', index: int|None = None): if __name__ == '__main__': import music21 music21.mainTest() - diff --git a/music21/stream/base.py b/music21/stream/base.py index 87cdfcc4fe..09808e02e4 100644 --- a/music21/stream/base.py +++ b/music21/stream/base.py @@ -7987,7 +7987,7 @@ def flatten(self: StreamType, retainContainers=False) -> StreamType: sNew_derivation.method = method sNew.derivation = sNew_derivation - + # storing .elements in here necessitates # create a new, independent cache instance in the flat representation sNew._cache = {} diff --git a/music21/style.py b/music21/style.py index c241ebc356..c402c7cf2d 100644 --- a/music21/style.py +++ b/music21/style.py @@ -102,45 +102,25 @@ def __init__(self) -> None: self.dashLength: float|int|None = None self.spaceLength: float|int|None = None - def _getEnclosure(self) -> Enclosure|None: - return self._enclosure - def _setEnclosure(self, value: Enclosure|None): - if value is None: - self._enclosure = value - elif value == Enclosure.NONE: - self._enclosure = None - elif isinstance(value, Enclosure): - self._enclosure = value - elif isinstance(value, str): - try: - enc_value = Enclosure(value.lower()) - except ValueError as ve: - raise TextFormatException(f'Not a supported enclosure: {value!r}') from ve - - self._enclosure = enc_value - - else: - raise TextFormatException(f'Not a supported enclosure: {value!r}') - - enclosure = property(_getEnclosure, - _setEnclosure, - doc=''' + @property + def enclosure(self) -> Enclosure|None: + ''' Get or set the enclosure as a style.Enclosure enum or None. - Valid names are - "rectangle"/style.Enclosure.RECTANGLE, - "square"/style.Enclosure.SQUARE, - "oval"/style.Enclosure.OVAL, - "circle"/style.Enclosure.CIRCLE, - "bracket"/style.Enclosure.BRACKET, - "inverted-bracket"/style.Enclosure.INVERTED_BRACKET (output in musicxml 4 only) - None/"none"/style.Enclosure.NONE (returns Python None object) + Valid names are: + + * "rectangle"/style.Enclosure.RECTANGLE, + * "square"/style.Enclosure.SQUARE, + * "oval"/style.Enclosure.OVAL, + * "circle"/style.Enclosure.CIRCLE, + * "bracket"/style.Enclosure.BRACKET, + * "inverted-bracket"/style.Enclosure.INVERTED_BRACKET (output in musicxml 4 only) + * None/"none"/style.Enclosure.NONE (returns Python None object) or the following other shapes with their ALLCAPS Enclosure equivalents: - triangle, diamond, - pentagon, hexagon, heptagon, octagon, + triangle, diamond, pentagon, hexagon, heptagon, octagon, nonagon, or decagon. >>> tst = style.TextStyle() @@ -172,7 +152,27 @@ def _setEnclosure(self, value: Enclosure|None): Traceback (most recent call last): music21.style.TextFormatException: Not a supported enclosure: 4 - ''') + ''' + return self._enclosure + + @enclosure.setter + def enclosure(self, value: Enclosure|None): + if value is None: + self._enclosure = value + elif value == Enclosure.NONE: + self._enclosure = None + elif isinstance(value, Enclosure): + self._enclosure = value + elif isinstance(value, str): + try: + enc_value = Enclosure(value.lower()) + except ValueError as ve: + raise TextFormatException(f'Not a supported enclosure: {value!r}') from ve + + self._enclosure = enc_value + + else: + raise TextFormatException(f'Not a supported enclosure: {value!r}') def _getAbsoluteY(self): return self._absoluteY From 1394dbcdb77a8315c7d7ed4941c1f5567bf1de51 Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Tue, 17 Sep 2024 00:14:49 -1000 Subject: [PATCH 4/5] More lints --- music21/chord/__init__.py | 7 +++++-- music21/derivation.py | 2 ++ music21/note.py | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/music21/chord/__init__.py b/music21/chord/__init__.py index c3032f714f..4ae6d64a97 100644 --- a/music21/chord/__init__.py +++ b/music21/chord/__init__.py @@ -42,7 +42,7 @@ if t.TYPE_CHECKING: from music21 import stream - + from music21.style import Style environLocal = environment.Environment('chord') @@ -4195,9 +4195,12 @@ def setColor(self, value, pitchTarget=None): # assign to base if pitchTarget is None and self._notes: chord_style = self.style + if t.TYPE_CHECKING: + assert isintance(chord_style, Style) chord_style.color = value for n in self._notes: - n.style.color = value + n_style = n.style + n_style.color = value return elif isinstance(pitchTarget, str): diff --git a/music21/derivation.py b/music21/derivation.py index 223bf1695d..b9d19ac9b0 100644 --- a/music21/derivation.py +++ b/music21/derivation.py @@ -243,6 +243,8 @@ def chain(self) -> Generator[base.Music21Object, None, None]: orig: base.Music21Object | None = self.origin while orig is not None: yield orig + if t.TYPE_CHECKING: + assert orig is not None orig = orig.derivation.origin @property diff --git a/music21/note.py b/music21/note.py index 37a2e9e55b..082eb23994 100644 --- a/music21/note.py +++ b/music21/note.py @@ -43,6 +43,8 @@ from music21 import chord from music21 import instrument from music21 import percussion + from music21.style import Style + _NotRestType = t.TypeVar('_NotRestType', bound='NotRest') environLocal = environment.Environment('note') @@ -2095,7 +2097,10 @@ def testBasic(self): b = note.Note() b.quarterLength = qLen b.name = pitchName - b.style.color = '#FF00FF' + b_style = b.style + if t.TYPE_CHECKING: + assert isinstance(b_style, Style) + b_style.color = '#FF00FF' a.append(b) if self.show: From 5303e539423e9818d56f3484801c517a6901b4d9 Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Tue, 17 Sep 2024 00:27:33 -1000 Subject: [PATCH 5/5] done playing nice w/ pylint. --- music21/chord/__init__.py | 14 +++++--------- music21/derivation.py | 4 +--- music21/note.py | 6 ++---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/music21/chord/__init__.py b/music21/chord/__init__.py index 4ae6d64a97..37f7ad410d 100644 --- a/music21/chord/__init__.py +++ b/music21/chord/__init__.py @@ -3684,7 +3684,7 @@ def removeRedundantPitches(self, *, inPlace=False): note name in two different octaves is retained. If `inPlace` is True, a copy is not made and a list of deleted pitches is returned; - otherwise a copy is made and that copy is returned. + otherwise make and return a copy. >>> c1 = chord.Chord(['c2', 'e3', 'g4', 'e3']) >>> c1 @@ -4194,14 +4194,10 @@ def setColor(self, value, pitchTarget=None): ''' # assign to base if pitchTarget is None and self._notes: - chord_style = self.style - if t.TYPE_CHECKING: - assert isintance(chord_style, Style) - chord_style.color = value + # Pylint going crazy here + self.style.color = value # pylint: disable=attribute-defined-outside-init for n in self._notes: - n_style = n.style - n_style.color = value - + n.style.color = value # pylint: disable=attribute-defined-outside-init return elif isinstance(pitchTarget, str): pitchTarget = pitch.Pitch(pitchTarget) @@ -4351,7 +4347,7 @@ def setNoteheadFill(self, nh, pitchTarget): None False - By default assigns to first pitch: + By default, assigns to first pitch: >>> c3 = chord.Chord('C3 F4') >>> c3.setNoteheadFill(False, None) diff --git a/music21/derivation.py b/music21/derivation.py index b9d19ac9b0..0ca9ba4d33 100644 --- a/music21/derivation.py +++ b/music21/derivation.py @@ -243,9 +243,7 @@ def chain(self) -> Generator[base.Music21Object, None, None]: orig: base.Music21Object | None = self.origin while orig is not None: yield orig - if t.TYPE_CHECKING: - assert orig is not None - orig = orig.derivation.origin + orig = orig.derivation.origin # pylint: disable=no-member @property def method(self) -> str|None: diff --git a/music21/note.py b/music21/note.py index 082eb23994..52b2c22b93 100644 --- a/music21/note.py +++ b/music21/note.py @@ -2097,10 +2097,8 @@ def testBasic(self): b = note.Note() b.quarterLength = qLen b.name = pitchName - b_style = b.style - if t.TYPE_CHECKING: - assert isinstance(b_style, Style) - b_style.color = '#FF00FF' + # Pylint going crazy here + b.style.color = '#FF00FF' # pylint: disable=attribute-defined-outside-init a.append(b) if self.show: