diff options
author | Will Roberts <wildwilhelm@gmail.com> | 2017-06-08 08:03:04 +0200 |
---|---|---|
committer | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2017-06-07 23:03:04 -0700 |
commit | 0ecdc525146ecec9d1549ebf59404c769637a512 (patch) | |
tree | 2b37e56ef0ce6ac198d6ffc622da6f01c91ad4ef /Lib/test/test_itertools.py | |
parent | 5edf827c8052958b9d293f75ce8d93b66c1d58da (diff) | |
download | cpython-git-0ecdc525146ecec9d1549ebf59404c769637a512.tar.gz |
bpo-30537: use PyNumber in itertools.islice instead of PyLong (#1918)
* bpo-30537: use PyNumber in itertools instead of PyLong
* bpo-30537: revert changes except to islice_new
* bpo-30537: test itertools.islice and add entry to Misc/NEWS
Diffstat (limited to 'Lib/test/test_itertools.py')
-rw-r--r-- | Lib/test/test_itertools.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index f525255011..50cf1488ec 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -1243,6 +1243,19 @@ class TestBasicOps(unittest.TestCase): support.gc_collect() self.assertIsNone(wr()) + # Issue #30537: islice can accept integer-like objects as + # arguments + class IntLike(object): + def __init__(self, val): + self.val = val + def __index__(self): + return self.val + self.assertEqual(list(islice(range(100), IntLike(10))), list(range(10))) + self.assertEqual(list(islice(range(100), IntLike(10), IntLike(50))), + list(range(10, 50))) + self.assertEqual(list(islice(range(100), IntLike(10), IntLike(50), IntLike(5))), + list(range(10,50,5))) + def test_takewhile(self): data = [1, 3, 5, 20, 2, 4, 6, 8] self.assertEqual(list(takewhile(underten, data)), [1, 3, 5]) |