Skip to content
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

Wrong sign placement in PyUnicode_FromFormat #95504

Closed
philg314 opened this issue Jul 31, 2022 · 1 comment
Closed

Wrong sign placement in PyUnicode_FromFormat #95504

philg314 opened this issue Jul 31, 2022 · 1 comment
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@philg314
Copy link
Contributor

Bug report

When specifying width or precision with a negative number the sign ignores that and sticks to the number.
Width specifies the minimum output width, so if the zero flag is set the sign should be the first character of the width padding, if the zero flag is not set the last character of the padding.
Precision specifies the number of digits, so the sign should be placed before precision count digits.

PyUnicode_FromFormat(  "%05d", -123); //   "0-123" should be   "-0123"
PyUnicode_FromFormat(  "%.5d", -123); //   "0-123" should be  "-00123"
PyUnicode_FromFormat( "%7.5d", -123); // "  0-123" should be " -00123"
PyUnicode_FromFormat("%07.5d", -123); // "000-123" should be "-000123"

Your environment

  • CPython versions tested on: main branch
@philg314 philg314 added the type-bug An unexpected behavior, bug, or error label Jul 31, 2022
encukou added a commit that referenced this issue Aug 10, 2022
Co-authored-by: philg314 <110174000+philg314@users.noreply.github.com>
@kumaraditya303
Copy link
Contributor

Fixed by #95848

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants