Skip to content

Handle non-mapping operands in Index equality - #388

Open
pabszero wants to merge 2 commits into
grantjenks:masterfrom
pabszero:fix-index-comparison-protocol
Open

pabszero wants to merge 2 commits into
grantjenks:masterfrom
pabszero:fix-index-comparison-protocol

Conversation

@pabszero

Copy link
Copy Markdown

An empty Index currently compares equal to an empty list or string, while comparisons with None or a same-length nonempty list raise TypeError/AttributeError. Return NotImplemented for non-mappings in both equality methods, allowing Python to try the other operand's reflected comparison.

Fixes #387. Preserve the existing order-sensitive Index/OrderedDict comparisons and order-insensitive general mapping comparisons. This is independent of #378, which addresses missing-key sentinel collisions between mappings.

Validation on Windows:

  • New comparison cases: 17 failures and 4 passing mapping controls before the fix; all 21 pass afterward. They cover empty/populated Index objects, both operand orders, equality/inequality, reflected methods and mapping order.
  • Full suite including tutorial doctests: 272 tests and 12 subtests pass on both CPython 3.12.14 and 3.13.5; 99.04% branch-aware coverage (98% required).
  • Blue, isort and Flake8 7.4.1 pass on changed files; mypy and Pylint 2.17.7 pass on all library modules (Pylint on Python 3.12). git diff --check passes. Published source/test bytes match the tested files.
  • Test runs report Django USE_L10N deprecation warnings; Python 3.12 uses coverage's Python tracer fallback, and Python 3.13 also reports SQLite ResourceWarnings from the existing suite. Other platforms/versions and hosted CI are unverified.

Found through code inspection and prepared/tested with OpenAI Codex assistance under the account owner's OSS contribution request. No production incident or independent human review is claimed.

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.

Index equality raises or reports equality when comparing non-mappings

1 participant