From 256f8f9f6e68bc54cfb9bdc675db4e61b951146b Mon Sep 17 00:00:00 2001 From: Alex Khomchenko Date: Sun, 27 Aug 2017 15:30:39 +0200 Subject: [PATCH 1/3] added test for equality with other abc.Mapping impl --- tests/test_multidict.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_multidict.py b/tests/test_multidict.py index db22f1573..ddb3f25da 100644 --- a/tests/test_multidict.py +++ b/tests/test_multidict.py @@ -187,6 +187,11 @@ def test_eq3(self): d2 = self.make_dict() self.assertNotEqual(d1, d2) + def test_eq_other_mapping_contains_more_keys(self): + d1 = self.make_dict(foo='bar') + d2 = dict(foo='bar', bar='baz') + self.assertNotEqual(d1, d2) + def test_ne(self): d = self.make_dict([('key', 'value1')]) self.assertNotEqual(d, {'key': 'another_value'}) From 318ecf8c8ae486739dec6d51f8041593a4e88915 Mon Sep 17 00:00:00 2001 From: Alex Khomchenko Date: Sun, 27 Aug 2017 15:47:54 +0200 Subject: [PATCH 2/3] fixed issue with eq check when other contains more keys --- multidict/_multidict_py.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/multidict/_multidict_py.py b/multidict/_multidict_py.py index 89382cf45..48d365a76 100644 --- a/multidict/_multidict_py.py +++ b/multidict/_multidict_py.py @@ -120,6 +120,8 @@ def __eq__(self, other): if i1 != i2 or v1 != v2: return False return True + if len(self) != len(other): + return False for k, v in self.items(): nv = other.get(k, _marker) if v != nv: From b947a0ce5c96f6178a4e81f31ce4b92f2bb0a2e1 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 28 Aug 2017 09:46:07 +0300 Subject: [PATCH 3/3] Update _multidict_py.py --- multidict/_multidict_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multidict/_multidict_py.py b/multidict/_multidict_py.py index 48d365a76..26fbd5b09 100644 --- a/multidict/_multidict_py.py +++ b/multidict/_multidict_py.py @@ -120,7 +120,7 @@ def __eq__(self, other): if i1 != i2 or v1 != v2: return False return True - if len(self) != len(other): + if len(self._impl._items) != len(other): return False for k, v in self.items(): nv = other.get(k, _marker)