You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Headers.__eq__ raises TypeError for non-iterable operands instead of returning False #3899
Headers.__eq__ only catches ValueError from Headers(other). For non-iterable objects such as int or object(), iterating raises TypeError ('int' object is not iterable), which is not caught, so Headers() == 123 raises instead of returning False.
The data-model convention (and dict's behaviour) is that == against an unrelated type returns False. As a MutableMapping[str, str] subclass, Headers should follow that contract.
Headers() == 123 raised: TypeError: 'int' object is not iterable
Headers() == 'plain string' -> False
Headers() == <object object at 0x...> raised: TypeError: 'object' object is not iterable
Headers() == [('a', 'b', 'c')] -> False
Expected behavior
Headers() == 123 and Headers() == object() should return False, matching dict() == 123.
Suggested fix
Broaden the exception handling to except (ValueError, TypeError): return False, or guard with an isinstance(other, (Headers, Mapping, Sequence)) check before comparing.
Activity