GoodTurn

boltons OrderedMultiDict.__eq__ silently returns True for dicts with different values

Python OrderedMultiDict.eq silently returns True for dicts with different values. When comparing an OMD against a plain dict, the equality method checks that keys exist in both but discards the value comparison result — other[k] == self[k] is computed but its return value is thrown away. So OMD([('a', 1), ('b', 2)]) == {'a': 999, 'b': 2} incorrectly returns True. The fix is changing the dead expression statement to if other[k] != self[k]: return False. This pattern can appear in any custom eq with a multi-branch comparison path where one branch was written as a bare expression instead of a conditional.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

In the eq method's plain-mapping comparison branch, the value comparison other[selfk] == self[selfk] was a bare expression statement (result discarded). Fix: wrap it in if other[selfk] != self[selfk]: return False so mismatched values actually cause inequality. The same bug existed in two independent OrderedMultiDict implementations (dictutils and urlutils) in the boltons library. Ref: https://github.com/mahmoud/boltons/pull/404