mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
3d4ca74bc8
commit
4a1f593df5
4 changed files with 62 additions and 2 deletions
|
@ -117,6 +117,33 @@ class GeneralFloatCases(unittest.TestCase):
|
|||
self.assertRaises(OverflowError, float('-inf').as_integer_ratio)
|
||||
self.assertRaises(ValueError, float('nan').as_integer_ratio)
|
||||
|
||||
def test_float_containment(self):
|
||||
floats = (INF, -INF, 0.0, 1.0, NAN)
|
||||
for f in floats:
|
||||
self.assert_(f in [f], "'%r' not in []" % f)
|
||||
self.assert_(f in (f,), "'%r' not in ()" % f)
|
||||
self.assert_(f in {f}, "'%r' not in set()" % f)
|
||||
self.assert_(f in {f: None}, "'%r' not in {}" % f)
|
||||
self.assertEqual([f].count(f), 1, "[].count('%r') != 1" % f)
|
||||
self.assert_(f in floats, "'%r' not in container" % f)
|
||||
|
||||
for f in floats:
|
||||
# nonidentical containers, same type, same contents
|
||||
self.assert_([f] == [f], "[%r] != [%r]" % (f, f))
|
||||
self.assert_((f,) == (f,), "(%r,) != (%r,)" % (f, f))
|
||||
self.assert_({f} == {f}, "{%r} != {%r}" % (f, f))
|
||||
self.assert_({f : None} == {f: None}, "{%r : None} != "
|
||||
"{%r : None}" % (f, f))
|
||||
|
||||
# identical containers
|
||||
l, t, s, d = [f], (f,), {f}, {f: None}
|
||||
self.assert_(l == l, "[%r] not equal to itself" % f)
|
||||
self.assert_(t == t, "(%r,) not equal to itself" % f)
|
||||
self.assert_(s == s, "{%r} not equal to itself" % f)
|
||||
self.assert_(d == d, "{%r : None} not equal to itself" % f)
|
||||
|
||||
|
||||
|
||||
class FormatFunctionsTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue