diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-12 18:44:06 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-12 18:44:06 (GMT) |
commit | 1872b1c01f343f4cbfa7696ce95beae8278ce210 (patch) | |
tree | 382d8080c87b1484d3449b9108f65b023ccdaef8 /Lib | |
parent | 8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf (diff) | |
download | cpython-1872b1c01f343f4cbfa7696ce95beae8278ce210.zip cpython-1872b1c01f343f4cbfa7696ce95beae8278ce210.tar.gz cpython-1872b1c01f343f4cbfa7696ce95beae8278ce210.tar.bz2 |
Fix a couple of bugs exposed by the new __index__ code. The 64-bit buildbots
were failing due to inappropriate clipping of numbers larger than 2**31
with new-style classes. (typeobject.c) In reviewing the code for classic
classes, there were 2 problems. Any negative value return could be returned.
Always return -1 if there was an error. Also make the checks similar
with the new-style classes. I believe this is correct for 32 and 64 bit
boxes, including Windows64.
Add a test of classic classes too.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_index.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/test/test_index.py b/Lib/test/test_index.py index b224a50..1081b53 100644 --- a/Lib/test/test_index.py +++ b/Lib/test/test_index.py @@ -181,8 +181,8 @@ class OverflowTestCase(unittest.TestCase): self.assertEqual(self.pos.__index__(), self.pos) self.assertEqual(self.neg.__index__(), self.neg) - def test_getitem(self): - class GetItem(object): + def _getitem_helper(self, base): + class GetItem(base): def __len__(self): return maxint def __getitem__(self, key): @@ -195,6 +195,13 @@ class OverflowTestCase(unittest.TestCase): self.assertEqual(x[self.neg:self.pos], (-1, maxint)) self.assertEqual(x[self.neg:self.pos:1].indices(maxint), (0, maxint, 1)) + def test_getitem(self): + self._getitem_helper(object) + + def test_getitem_classic(self): + class Empty: pass + self._getitem_helper(Empty) + def test_sequence_repeat(self): self.failUnlessRaises(OverflowError, lambda: "a" * self.pos) self.failUnlessRaises(OverflowError, lambda: "a" * self.neg) |