Skip to content

Preserve equality fallback for unsupported header operands - #215

Open
wynneyin wants to merge 2 commits into
python-hyper:masterfrom
wynneyin:fix/header-equality-fallback
Open

wynneyin wants to merge 2 commits into
python-hyper:masterfrom
wynneyin:fix/header-equality-fallback

Conversation

@wynneyin

@wynneyin wynneyin commented Nov 8, 2026

Copy link
Copy Markdown

Related to #214.

Comparing event headers with None, an integer or an ordinary sentinel currently raises TypeError. Comparing them with unittest.mock.ANY also raises before the other operand can handle the comparison.

Return NotImplemented when the operand's type supports neither the iterator protocol nor the legacy __getitem__ sequence protocol. Otherwise retain the existing content comparison. This preserves iterable comparisons and exceptions from both iterator initialization and consumption.

Regression tests cover equality and inequality in both operand orders, reflected comparison with ANY, existing lists/tuples/iterators/header objects, legacy sequences, and iterator setup/consumption errors. AI-assisted contribution with an independent read-only review; the review's iterator-setup finding was reproduced and corrected.

Validation on macOS arm64:

  • Original implementation: 4 failed, 6 passed in the initial focused suite.
  • Final implementation: 86 passed on each of Python 3.10.19, 3.11.14, 3.12.7, 3.13.9 and 3.14.0.
  • Full Black and isort checks pass; strict mypy passes across 22 source files.
  • Original suite: 78 passed, statement/branch coverage 98.2%. Final suite: 86 passed, coverage 98.2%, with the same 19 uncovered statements and all added branches covered. The baseline run deselected the new tests and used the original production implementation.
  • git diff --check passes.
  • Python 3.8, 3.9 and PyPy were not tested locally.

🤖 Generated with Claude Code

wynneyin and others added 2 commits November 8, 2026 18:21
Return NotImplemented for operands without an iteration protocol so
sentinel comparisons and reflected equality work for event headers.
Keep existing iterable comparisons and iteration exceptions intact.

Add regression coverage for unsupported operands, reflected equality,
legacy sequences and errors during iterator setup and consumption.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Document the user-visible sentinel and reflected-comparison repair
tracked in issue python-hyper#214.

Co-Authored-By: Claude Code <noreply@anthropic.com>
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.

1 participant