Skip to content

feat(parsers): Add __eq__ and __hash__ to Param#80

Merged
ericchansen merged 2 commits intomasterfrom
feat/param-equality
Mar 20, 2026
Merged

feat(parsers): Add __eq__ and __hash__ to Param#80
ericchansen merged 2 commits intomasterfrom
feat/param-equality

Conversation

@ericchansen
Copy link
Copy Markdown
Owner

Summary

Add __eq__ and __hash__ to Param so parameters can be compared, deduplicated, and used in sets.

Changes

  • q2mm/parsers/param.py -- Add __eq__ and __hash__ based on (ptype, ff_row, ff_col) identity tuple
  • test/test_param.py -- New test suite (19 tests) covering equality, hashing, set operations, construction, angle normalization, and range validation

Why

The original authors noted this was needed ("Need a general index scheme to compare the equalness of two parameters"). Without __eq__, comparing params required manual ff_row/ff_col checks, and params couldn't be used in sets or as dict keys.

Testing

  • 19 new tests, all passing
  • 188 passed, 19 skipped total (fast tier)

Closes #78

Parameter identity is defined by (ptype, ff_row, ff_col). This
enables set operations, deduplication, and cleaner test assertions.

Includes comprehensive test suite for equality, construction,
angle normalization, and range validation (19 new tests).

Closes #78

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds value-based identity semantics to q2mm.parsers.param.Param so parameters can be compared/deduplicated and used as set/dict keys, with a new pytest suite covering equality/hashing and existing value normalization/range behavior.

Changes:

  • Implement Param.__eq__ and Param.__hash__ using (ptype, ff_row, ff_col) as the identity tuple.
  • Add test/test_param.py with tests for equality/hashing, set behavior, construction, angle normalization, and range validation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
q2mm/parsers/param.py Adds __eq__/__hash__ to make Param comparable and hashable by FF position.
test/test_param.py Introduces a pytest suite validating the new equality/hashing behavior and related Param behaviors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread q2mm/parsers/param.py
Comment thread q2mm/parsers/param.py
Params with None in (ptype, ff_row, ff_col) now:
- Return NotImplemented from __eq__ (falls back to identity)
- Raise TypeError from __hash__ (prevents accidental set collisions)
- Add self-identity fast path (self is other)
- Document mutability constraint on identity fields in __hash__ docstring

Adds 3 new tests for edge cases (22 total in test_param.py).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ericchansen ericchansen merged commit 8ca6116 into master Mar 20, 2026
5 checks passed
@ericchansen ericchansen deleted the feat/param-equality branch March 20, 2026 15:18
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.

feat: Add __eq__ and __hash__ to Param for equality comparison

2 participants