mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
No longer ignore exceptions raised by comparisons during key lookup.
Inspired by Armin Rigo's suggestion to do the same with dictionaries.
This commit is contained in:
parent
c404ff2f2d
commit
9bda1d6f64
2 changed files with 61 additions and 48 deletions
|
@ -15,6 +15,12 @@ def check_pass_thru():
|
|||
raise PassThru
|
||||
yield 1
|
||||
|
||||
class BadCmp:
|
||||
def __hash__(self):
|
||||
return 1
|
||||
def __cmp__(self, other):
|
||||
raise RuntimeError
|
||||
|
||||
class TestJointOps(unittest.TestCase):
|
||||
# Tests common to both set and frozenset
|
||||
|
||||
|
@ -227,6 +233,17 @@ class TestJointOps(unittest.TestCase):
|
|||
f.add(s)
|
||||
f.discard(s)
|
||||
|
||||
def test_badcmp(self):
|
||||
s = self.thetype([BadCmp()])
|
||||
# Detect comparison errors during insertion and lookup
|
||||
self.assertRaises(RuntimeError, self.thetype, [BadCmp(), BadCmp()])
|
||||
self.assertRaises(RuntimeError, s.__contains__, BadCmp())
|
||||
# Detect errors during mutating operations
|
||||
if hasattr(s, 'add'):
|
||||
self.assertRaises(RuntimeError, s.add, BadCmp())
|
||||
self.assertRaises(RuntimeError, s.discard, BadCmp())
|
||||
self.assertRaises(RuntimeError, s.remove, BadCmp())
|
||||
|
||||
class TestSet(TestJointOps):
|
||||
thetype = set
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue