diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2008-11-12 23:23:36 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2008-11-12 23:23:36 (GMT) |
commit | 4a1f593df5d4733831a1c4f03ca40c701433c43d (patch) | |
tree | 0aea7b57d9c6fad40a32cca6be0993bd607ed9e2 /Lib/test/test_contains.py | |
parent | 3d4ca74bc85c4224498e75704f82e4d42b6a04df (diff) | |
download | cpython-4a1f593df5d4733831a1c4f03ca40c701433c43d.zip cpython-4a1f593df5d4733831a1c4f03ca40c701433c43d.tar.gz cpython-4a1f593df5d4733831a1c4f03ca40c701433c43d.tar.bz2 |
Issue #4296: Fix PyObject_RichCompareBool so that "x in [x]" evaluates to
True, even when x doesn't compare equal to itself. This was a regression
from 2.6.
Reviewed by R. Hettinger and C. Heimes.
Diffstat (limited to 'Lib/test/test_contains.py')
-rw-r--r-- | Lib/test/test_contains.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/Lib/test/test_contains.py b/Lib/test/test_contains.py index e570787..39c61bd 100644 --- a/Lib/test/test_contains.py +++ b/Lib/test/test_contains.py @@ -1,3 +1,4 @@ +from collections import deque from test.support import run_unittest import unittest @@ -6,7 +7,7 @@ class base_set: def __init__(self, el): self.el = el -class set(base_set): +class myset(base_set): def __contains__(self, el): return self.el == el @@ -17,7 +18,7 @@ class seq(base_set): class TestContains(unittest.TestCase): def test_common_tests(self): a = base_set(1) - b = set(1) + b = myset(1) c = seq(1) self.assert_(1 in b) self.assert_(0 not in b) @@ -80,6 +81,25 @@ class TestContains(unittest.TestCase): except TypeError: pass + def test_nonreflexive(self): + # containment and equality tests involving elements that are + # not necessarily equal to themselves + + class MyNonReflexive(object): + def __eq__(self, other): + return False + def __hash__(self): + return 28 + + values = float('nan'), 1, None, 'abc', MyNonReflexive() + constructors = list, tuple, dict.fromkeys, set, frozenset, deque + for constructor in constructors: + container = constructor(values) + for elem in container: + self.assert_(elem in container) + self.assert_(container == constructor(values)) + self.assert_(container == container) + def test_main(): run_unittest(TestContains) |