Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating duplicative ChordStepModifications #1509

Merged
merged 7 commits into from
Jan 14, 2023

Conversation

jacobtylerwalls
Copy link
Member

Fixes #1500 by not creating duplicative ChordStepModifications.

Also:

  • Avoid unnecessary casting to tuple and back in _adjustPitchesForChordStepModifications()
  • Default ChordStepModification.interval to perfect unison to avoid None != Interval('P1')

@jacobtylerwalls jacobtylerwalls changed the title Figure idempotent Avoid creating duplicative ChordStepModifications Jan 2, 2023
@coveralls
Copy link

coveralls commented Jan 2, 2023

Coverage Status

Coverage: 93.052% (+0.004%) from 93.048% when pulling 34aa5da on figure-idempotent into e5f40b0 on master.

Copy link
Member

@mscuthbert mscuthbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good to me -- the problem with the default P1 interval though seems an issue; people love to transpose intervals inPlace and then our default is gone. Once that's in, feel free to merge.

self._interval = None # alteration of degree, alter ints in mxl
self._degree = None # the degree number, where 3 is the third
# use properties if defined
def __init__(self, modType=None, degree=None, intervalObj=interval.Interval('P1')):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure about this change because Interval is mutable. We definitely need an immutable flag on Interval so that this default value isn't ever transposed inPlace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! 34aa5da

# use properties if defined
def __init__(self, modType=None, degree=None, intervalObj=interval.Interval('P1')):
self._modType: str | None = None # add, alter, subtract
self._interval: interval.Interval | None = None # alteration of degree, alter ints in mxl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to make it so _interval is always an Interval and never None? Helps with the typing.

self._degree = None # the degree number, where 3 is the third
# use properties if defined
def __init__(self, modType=None, degree=None, intervalObj=interval.Interval('P1')):
self._modType: str | None = None # add, alter, subtract
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can use '' for None going forward. There were a lot of str | None in the code before typing became a thing but now it's biting us.

def _adjustPitchesForChordStepModifications(self, pitches):
def _adjustPitchesForChordStepModifications(
self, pitches: t.Iterable[pitch.Pitch]
) -> list[pitch.Pitch]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal method. change of type is fine.

@jacobtylerwalls jacobtylerwalls requested review from mscuthbert and removed request for mscuthbert January 14, 2023 14:48
@jacobtylerwalls jacobtylerwalls merged commit 2e0ce4e into master Jan 14, 2023
@jacobtylerwalls jacobtylerwalls deleted the figure-idempotent branch January 14, 2023 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChordSymbol.figure setter is not idempotent
3 participants