Problem
The equal() helper in src/pythonnative/equality.py defines how hook dependencies and state snapshots signal a change. Its contract deliberately treats identity as equal, accepts a boolean comparison result, and treats exceptions or nonboolean comparison results as unequal without coercing them to bool.
src/pythonnative/hooks.py uses it for dependency comparison and state updates. The test suite has Element equality tests, but no direct tests for this helper's unusual-comparison behavior. Replacing it with a naive bool(left == right) would break array-like application values.
Requested change
Add tests/test_equality.py with focused tests of the existing behavior. Use tiny custom Python classes to model unusual comparisons so contributors don't need NumPy or another new dependency.
Acceptance criteria
- Equal and unequal ordinary scalar/container values return actual booleans.
- The same object returns True without invoking its __eq__, even if that method would raise.
- Distinct objects whose comparison raises return False.
- A nonboolean comparison result returns False without calling the result's __bool__; make that method raise to prove it isn't called.
- A truthy nonboolean result such as integer 1 isn't treated as boolean True.
- Include a case documenting that reusing the same mutable object doesn't signal a change after an in-place mutation.
This task adds regression coverage for the existing snapshot contract; it doesn't change equality rules or hook APIs.
Verification
uv run pytest tests/test_equality.py tests/test_hooks.py -q
./scripts/check.sh
Suggested commit message
Following CONTRIBUTING.md:
test(equality): cover identity and nonboolean comparison results
Before starting
Please follow the issue-claiming process: check for an assignee or linked pull request, comment to claim the issue, and wait for a maintainer to assign it before opening a pull request. Contributor setup is in CONTRIBUTING.md.
Problem
The equal() helper in src/pythonnative/equality.py defines how hook dependencies and state snapshots signal a change. Its contract deliberately treats identity as equal, accepts a boolean comparison result, and treats exceptions or nonboolean comparison results as unequal without coercing them to bool.
src/pythonnative/hooks.py uses it for dependency comparison and state updates. The test suite has Element equality tests, but no direct tests for this helper's unusual-comparison behavior. Replacing it with a naive bool(left == right) would break array-like application values.
Requested change
Add tests/test_equality.py with focused tests of the existing behavior. Use tiny custom Python classes to model unusual comparisons so contributors don't need NumPy or another new dependency.
Acceptance criteria
This task adds regression coverage for the existing snapshot contract; it doesn't change equality rules or hook APIs.
Verification
Suggested commit message
Following CONTRIBUTING.md:
Before starting
Please follow the issue-claiming process: check for an assignee or linked pull request, comment to claim the issue, and wait for a maintainer to assign it before opening a pull request. Contributor setup is in CONTRIBUTING.md.