-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-126992: Change pickle code to base 10 for load_long and load_int #127042
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.
LGTM
But see the issue thread. The discrepancy could be easily solved without backward-incompatible changes.
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 a NEWS entry: see https://devguide.python.org/ HOWTO (use blurb-it or blurb).
Just added a NEWS entry - I hope I did it right |
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.
LGTM
@serhiy-storchaka: Would you mind to double check this change? |
I am not sure that this is an issue. Non-decimal integers was accepted always. It was not documented, but user code may depend on it. We may even make it an official feature in future. |
There is still an inconsistency wrt pickle and pickletools.
What do you think on changing pickletools instead, as it was suggested in the issue thread? |
If consider pickletools as a debugging tool, making it more lenient is safer. |
Yeah the problem right now is that pickletools is LESS lenient because it ONLY accepts base 10, so if we want to keep the any-base feature in pickle, we should change |
@serhiy-storchaka Would you like me to change my pull request to update pickletools.py to accept any base? |
Take your time. In the end, the solution proposed in this PR may be the right solution. |
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.
After research and discussion I am inclined to accept this change. But please add tests. Test that prefixes 0x
, 0o
and 0b
are rejected, but leading 0
s are accepted and interpreted as decimals. Add also pickletools tests.
How do you want to write tests? Does it require to serialize to pickle manually (reimplement pickle in tests)? I don't think that tests are needed. |
There are already many similar tests. They try to unpickle the manually prepared data. I added tests. They fail without changes in this PR. |
@Legoclones, it seems you are new with Git and made a common error (don't be ashamed, it happened with me too) -- you added changes to your Now your fork is broken. To fix it, delete the |
Oh nice, I like your tests :-) I expected something way more complicated. |
@serhiy-storchaka I've had a busy week at school, so I haven't had time to write the tests yet. Thanks for doing that and getting it done. Also yeah, I realized I had committed my changes to main and not a separate branch, I'll have to recreate it. The tests look good, thanks for working with me on it! |
…_int (pythonGH-127042) Co-authored-by: Serhiy Storchaka <[email protected]>
To be in line with the documentation and sync behavior across all 3 pickle implementations,
load_int()
andload_long()
are changed to have the base explicitly set to 10 (like inpickletools.py
).INT
/LONG
base discrepancy #126992