-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-45018: Fix rangeiter_reduce in rangeobject.c #27938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dffa24e
c880127
bf3f944
e29696e
2df7177
7241068
2d57834
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -374,26 +374,41 @@ def test_pickling(self): | |
| list(r)) | ||
|
|
||
| def test_iterator_pickling(self): | ||
| testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1), | ||
| (13, 21, 3), (-2, 2, 2), (2**65, 2**65+2)] | ||
| testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1), (13, 21, 3), | ||
| (-2, 2, 2), (2**31-3, 2**31-1), (2**33, 2**33+2), | ||
| (2**63-3, 2**63-1), (2**65, 2**65+2)] | ||
| for proto in range(pickle.HIGHEST_PROTOCOL + 1): | ||
| for t in testcases: | ||
| it = itorg = iter(range(*t)) | ||
| data = list(range(*t)) | ||
|
|
||
| d = pickle.dumps(it, proto) | ||
| it = pickle.loads(d) | ||
| self.assertEqual(type(itorg), type(it)) | ||
| self.assertEqual(list(it), data) | ||
|
|
||
| it = pickle.loads(d) | ||
| try: | ||
| next(it) | ||
| except StopIteration: | ||
| continue | ||
| with self.subTest(proto=proto, t=t): | ||
| it = itorg = iter(range(*t)) | ||
| data = list(range(*t)) | ||
|
|
||
| d = pickle.dumps(it, proto) | ||
| it = pickle.loads(d) | ||
| self.assertEqual(type(itorg), type(it)) | ||
| self.assertEqual(list(it), data) | ||
|
|
||
| it = pickle.loads(d) | ||
| try: | ||
| next(it) | ||
| except StopIteration: | ||
| continue | ||
| d = pickle.dumps(it, proto) | ||
| it = pickle.loads(d) | ||
| self.assertEqual(list(it), data[1:]) | ||
|
|
||
| def test_iterator_pickling_overflowing_index(self): | ||
| for proto in range(pickle.HIGHEST_PROTOCOL + 1): | ||
| with self.subTest(proto=proto): | ||
| it = iter(range(2**32 + 2)) | ||
| _, _, idx = it.__reduce__() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test with Other Python implementations can use such range iterator implementation from start.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we include this test for now and adapt it once your proposed PR is up? I'm happy to review it then.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then other Python implementations will be limited in implementation of the range iterator.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the As I said, I fully support changing this test when/if we modify |
||
| self.assertEqual(idx, 0) | ||
| it.__setstate__(2**32 + 1) # undocumented way to set r->index | ||
| _, _, idx = it.__reduce__() | ||
| self.assertEqual(idx, 2**32 + 1) | ||
| d = pickle.dumps(it, proto) | ||
| it = pickle.loads(d) | ||
| self.assertEqual(list(it), data[1:]) | ||
| self.assertEqual(next(it), 2**32 + 1) | ||
|
|
||
ambv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_exhausted_iterator_pickling(self): | ||
| for proto in range(pickle.HIGHEST_PROTOCOL + 1): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed pickling of range iterators that iterated for over 2**32 times. |
Uh oh!
There was an error while loading. Please reload this page.