Skip to content

Fix equality check to handle TypeError - #216

Open
Affanasrar wants to merge 1 commit into
python-hyper:masterfrom
Affanasrar:fix-headers-equality-typeerror
Open

Affanasrar wants to merge 1 commit into
python-hyper:masterfrom
Affanasrar:fix-headers-equality-typeerror

Conversation

@Affanasrar

Copy link
Copy Markdown

Fixes #214

Root Cause

Headers.eq called list(other) directly without handling non-iterable types. When comparing against a non-iterable operand (such as None or unittest.mock.ANY), list(other) raised TypeError instead of returning NotImplemented to allow Python's equality fallback.

Fix

Wrapped the list comparison in a try-except TypeError block in Headers.eq to return NotImplemented when other is non-iterable.

Handle TypeError in equality comparison.

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The added try/except block is misindented: try is indented beyond the method body and except does not align with it. This makes _headers.py fail to import before the equality fix can run. Could you align the block and add a regression test for comparing Headers with a non-iterable operand?

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.

Header equality raises TypeError for non-iterable operands

2 participants