Visitar URL original
Allow reflected equality for non-pointer objects by wynneyin · Pull Request #112 · stefankoegl/python-json-pointer · GitHub
Skip to content

Allow reflected equality for non-pointer objects - #112

Merged
stefankoegl merged 1 commit into
stefankoegl:masterfrom
wynneyin:fix/reflected-equality
Nov 10, 2026
Merged

stefankoegl merged 1 commit into
stefankoegl:masterfrom
wynneyin:fix/reflected-equality

Conversation

@wynneyin

Copy link
Copy Markdown
Contributor

JsonPointer.__eq__ returns False for every non-pointer object, preventing Python from trying the other object's comparison. This makes JsonPointer('/a') == unittest.mock.ANY false while ANY == JsonPointer('/a') is true; != is also asymmetric.

Return NotImplemented for unsupported operand types so reflected comparison can run. Pointer-to-pointer equality and hashing are unchanged. Ordinary strings, numbers, None, and objects still compare unequal through Python's normal fallback.

Added regressions for == and != with the real unittest.mock.ANY in both operand orders, plus controls for ordinary unrelated types. Before the production change, the comparison suite had 2 failures and 9 passes; after, the complete 96-test suite passed on Python 3.10.19, 3.11.14, 3.12.7, 3.13.9, and 3.14.0 on macOS arm64.

Validation also passed: Flake8, git diff --check, CI-style unittest discovery with coverage (98%), sdist and wheel builds, twine check --strict, installed-wheel mypy.stubtest, and the strict Sphinx HTML build. Setuptools emitted its existing license-classifier deprecation warning. Linux, Windows, and PyPy were not tested locally. Review was inline; no independent reviewer was used.

Generated with Claude Code

Return NotImplemented for unsupported operand types so Python can try the
other object's comparison. This fixes asymmetric equality and inequality
with unittest.mock.ANY while preserving ordinary unequal-type fallback.

Add tests for both operand orders and unrelated built-in/object types.

Co-Authored-By: Claude Code <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the change enabling reflected equality comparisons with unsupported operand types.

No open issues 🎉

What changed in this PR

This PR allows JsonPointer comparisons with unsupported types to defer to the other operand’s equality implementation, fixing asymmetric comparisons with unittest.mock.ANY.

Changes:

  • Return NotImplemented for non-pointer operands, preserving pointer-to-pointer equality and hashing.
  • Add regression tests for reflected equality and inequality in both operand orders, plus controls for ordinary unrelated types.
File Description
tests.py Adds reflected-comparison regressions and unrelated-type controls.
jsonpointer.py Returns NotImplemented for unsupported equality operands.

Review effort: Balanced

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 98.87%. remained the same — wynneyin:fix/reflected-equality into stefankoegl:master

@stefankoegl
stefankoegl merged commit a52a5ff into stefankoegl:master Nov 10, 2026
24 checks passed
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.

4 participants