Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2167)

Unified Diff: Lib/test/test_dictviews.py

Issue 28189: dictitems_contains swallows compare errors
Patch Set: Created 3 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Objects/dictobject.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_dictviews.py Sat Sep 17 01:30:48 2016 +0300
+++ b/Lib/test/test_dictviews.py Sat Sep 17 23:14:03 2016 +0800
@@ -220,6 +220,30 @@
self.assertRaises((TypeError, pickle.PicklingError),
pickle.dumps, d.items(), proto)
+ def test_compare_error(self):
+ class Exc(Exception): pass
+ class BadEq:
+ def __hash__(self):
+ return 7
+ def __eq__(self, other):
+ raise Exc
+
+ k1, k2 = BadEq(), BadEq()
+ v1, v2 = BadEq(), BadEq()
+ d = {k1: v1}
+
+ self.assertIn(k1, d)
+ self.assertIn(k1, d.keys())
+ self.assertIn(v1, d.values())
+ self.assertIn((k1, v1), d.items())
+
+ self.assertRaises(Exc, d.__contains__, k2)
+ self.assertRaises(Exc, d.keys().__contains__, k2)
+ self.assertRaises(Exc, d.items().__contains__, (k2, v1))
+ self.assertRaises(Exc, d.items().__contains__, (k1, v2))
+ with self.assertRaises(Exc):
+ v2 in d.values()
+
def test_abc_registry(self):
d = dict(a=1)
« no previous file with comments | « no previous file | Objects/dictobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+