Repository navigation
Conversation
- Interval: return NotImplemented from __add__/__sub__ when RHS is not an Interval; guard rich comparisons the same way; return NotImplemented from __eq__ for non-Intervals; drop unused Interval._terms assignment - Pitch: normalize integral frequencies with int(self._frequency); guard ordering and __eq__ with isinstance; add __hash__ for consistency with __eq__ - Chord: use modern class syntax; guard __eq__ with isinstance; add __hash__ based on terms - Tests: Chord(M3) must not equal Interval(M3); that was accidental tuple equality via Interval._terms, not a supported API Co-authored-by: endolith <endolith@gmail.com>
cursor
Bot
force-pushed
the
cursor/oo-operator-protocol-2589
branch
from
June 12, 2026 04:44
6f26c95 to
9278817
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This addresses object-oriented / dunder-method issues in
just_intonation.py: correct use ofNotImplemented, type checks before touching the RHS, removal of dead state that caused misleading equality, and__hash__where__eq__is defined.Issues fixed
Interval.__add__/__sub__When the right-hand side was not an
Interval, these methods fell off the end and returnedNone, which breaks the numeric protocol and can surface as confusingTypeErrors. They now returnNotImplemented.Intervalrich comparisons and__eq____lt__/__gt__/__le__/__ge__called_F(b)for arbitraryb, which couldAttributeError(e.g.Interval(2, 1) < 2). They now requireisinstance(b, Interval)and otherwise returnNotImplemented.__eq__now returnsNotImplementedfor non-Intervaloperands so reflexive equality is handled correctly instead of blindly returningFalse.Interval._termsIt was only set on one constructor path, was never read anywhere in the repo, and happened to make
Chord(M3) == Interval(5, 4)true in tests by accidental tuple equality. That assignment was removed soIntervaldoes not carry misleading private state.Pitch.__init__After normalizing frequency, integral values were stored with
int(frequency)(the original argument) instead of the coerced value. It now usesint(self._frequency), which is correct whenfrequencyis already aPitchor other wrapped type.Pitchordering and__eq__Same pattern as
Interval:isinstance(b, Pitch)andNotImplementedinstead ofb.frequencyon arbitrary objects.Pitch.__hash__With
__eq__overridden, defining__hash__keeps hashing behavior explicit and consistent with equality (based on stored frequency).Chordclass Chord():→class Chord:.__eq__now checksisinstance(b, Chord)and returnsNotImplementedotherwise (avoidsAttributeErroronb._terms).__hash__added so chords can be used in sets/dicts like intervals.Test change
Chord(M3) == Interval(5, 4)was only true because of the removedInterval._termsquirk. The test now assertsChord(M3) != Interval(5, 4), which matches type-safe equality.Verification
pytest(full suite): 21 passedpytest --doctest-modules just_intonation.py: 17 passedflake8(syntax/undefined-name select on touched files): clean