-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add test and a NEWS entry.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
@serhiy-storchaka, I shortened the test per your suggestion. Now it indeed fails quickly without the patch:
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1): | ||
with self.subTest(proto=proto): | ||
it = iter(range(2**32 + 2)) | ||
_, _, idx = it.__reduce__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test with __reduce__
is fragile. I have an idea of making the range iterator more compact and faster. __reduce__()
will return different results, although pickle compatibility will be preserved.
Other Python implementations can use such range iterator implementation from start.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the __reduce__
part is fragile then probably so is __setstate__
. I think we should keep this so if an alternative implementation actually sees this failing, they have a chance of speaking up on BPO or realizing what this test is even doing.
As I said, I fully support changing this test when/if we modify __reduce__
behavior in CPython in the future. But for now I don't see a downside of including it. Calls to __reduce__
are already used in tests for descriptors, datetime, OrderedDict, and structseq.c
Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 94a3d2a) Co-authored-by: chilaxan <chilaxan@gmail.com>
GH-27990 is a backport of this pull request to the 3.10 branch. |
Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 94a3d2a) Co-authored-by: chilaxan <chilaxan@gmail.com>
GH-27991 is a backport of this pull request to the 3.9 branch. |
This commit changes an
i
to anl
asr->index
is a long not an inthttps://bugs.python.org/issue45018