Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-95504: Fix sign placement in PyUnicode_FromFormat#95505
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
philg314 commented Jul 31, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
ghost commented Jul 31, 2022 • edited by ghost
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by ghost
Uh oh!
There was an error while loading. Please reload this page.
methane left a comment
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 this is bit sensitive to backport because Python 3.11 is right before RC.
philg314 commented Aug 1, 2022
I emailed core-mentorship about this on Friday night but didn't wait to hear back before submitting this PR. @encukou is in the process of splitting _testcapimodule.c up into more manageable pieces (#93649) and has asked me to move Unicode related tests into a separate file. I'll convert this PR to a draft while working on that and convert it back once that's done. |
philg314 commented Aug 6, 2022
@encukou this is ready for review. |
serhiy-storchaka left a comment
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 in general, but I would wait for testcapi refactoring.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| if (negative&& !zeropad){ | ||
| if (_PyUnicodeWriter_WriteChar(writer, '-') ==-1) | ||
| returnNULL; | ||
| } |
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.
It can be simpler. Instead of writing minus explicitly, you can write it as a part of the buffer.
You will get the same result if remove this if and pass &buffer[negative && zeropad] instead of &buffer[negative] to _PyUnicodeWriter_WriteASCIIString().
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.
That wouldn't work with precision: %.5d with -123 would be 00-123.
encukou commented Aug 8, 2022
Sorry for making you do more work, but it works best if the test refactoring is done first, in a separate pull request, so that:
Do you want to split this up? I can also do it, and it wouldn't be too much extra work in addition to a review, but I don't want to “steal your contribution”. |
philg314 commented Aug 8, 2022
No problem, makes sense.
Sure, and for future reference I'll never have a problem with anything like that. Please ping me when the refactor is merged. |
encukou commented Aug 10, 2022
encukou commented Aug 10, 2022
philg314 commented Aug 10, 2022
Thanks for the reviews @methane and @serhiy-storchaka and thanks for merging @encukou! |
gh-95504: Fix sign placement in PyUnicode_FromFormat
The sign doesn't stick to the number anymore:
PyUnicode_FromFormat("%05d", -123); results in "-0123" instead of "0-123",
PyUnicode_FromFormat("%.5d", -123); results in "-00123" instead of "0-123".