[Bugfix] Color type missing __eq__/__ne__ despite having __hash__ #307

Closed
opened 2026-04-10 01:14:58 +00:00 by john · 0 comments
Owner

Context

The API consistency audit (docs/api-audit-2026-04.md, finding F6) identified that Color has __hash__ but no __eq__/__ne__ implementation (tp_richcompare). This means two Color objects with identical RGBA values may not compare equal using ==.

This violates the Python convention that objects with __hash__ should also implement __eq__.

Expected Behavior

c1 = mcrfpy.Color(255, 0, 0)
c2 = mcrfpy.Color(255, 0, 0)
assert c1 == c2  # Should be True
assert not (c1 != c2)  # Should be True

Action Items

  • Add tp_richcompare to PyColorType (compare r, g, b, a fields)
  • Add test for Color equality/inequality

Files

  • src/PyColor.h (type definition)
  • src/PyColor.cpp (implement richcompare)
## Context The API consistency audit (docs/api-audit-2026-04.md, finding F6) identified that `Color` has `__hash__` but no `__eq__`/`__ne__` implementation (`tp_richcompare`). This means two Color objects with identical RGBA values may not compare equal using `==`. This violates the Python convention that objects with `__hash__` should also implement `__eq__`. ## Expected Behavior ```python c1 = mcrfpy.Color(255, 0, 0) c2 = mcrfpy.Color(255, 0, 0) assert c1 == c2 # Should be True assert not (c1 != c2) # Should be True ``` ## Action Items - [ ] Add `tp_richcompare` to `PyColorType` (compare r, g, b, a fields) - [ ] Add test for Color equality/inequality ## Files - `src/PyColor.h` (type definition) - `src/PyColor.cpp` (implement richcompare)
john closed this issue 2026-04-10 01:19:07 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
john/McRogueFace#307
No description provided.