-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
gh-98836: Extend PyUnicode_FromFormat() #98838
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 1 commit
aca2393
4fdf596
13d4c97
e69d8b0
3bd9d3e
1e6094b
8942ca3
8481bda
8885850
9ffdb86
9ca3764
79a523c
91d8393
9f2f5f2
b86d92d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
* Support for conversion specifiers o (octal) and X (uppercase hexadecimal). * Support for length modifiers j (intmax_t) and t (ptrdiff_t). * Length modifiers are now applied to all integer conversions. * Support for wchar_t C strings (%ls and %lV). * Support for variable width and precision (*). * Support for flag - (left alignment).
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2880,10 +2880,11 @@ def check_format(expected, format, *args): | |
# check for crashes | ||
|
||
for fmt in (b'%', b'%0', b'%01', b'%.', b'%.1', | ||
b'%0%s', b'%1%s', b'%.%s', b'%.1%s', b'%1abc', | ||
b'%l', b'%ll', b'%z', b'%ls', b'%lls', b'%zs'): | ||
b'%l', b'%ll', b'%z', b'%lls', b'%zs'): | ||
with self.subTest(fmt=fmt): | ||
self.assertRaisesRegex(SystemError, 'invalid format string', | ||
PyUnicode_FromFormat, fmt, b'abc') | ||
|
||
self.assertRaisesRegex(SystemError, 'invalid format string', | ||
PyUnicode_FromFormat, b'%+i', c_int(10)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Add support of more formatting options (left aligning, octals, uppercase | ||
hexadecimals, :c:type:`intmax_t`, :c:type:`ptrdiff_t`, :c:type:`wchar_t` C | ||
strings, variable width and precision) in :c:func:`PyUnicode_FromFormat` and | ||
:c:func:`PyExc_Format`. |
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.
Can you please add something like
[[fill]align][sign][z][#][0][width][grouping_option][.precision][type]
? Example taken from: https://docs.python.org/dev/library/string.html#format-specification-mini-languageThe printf format is complex, and it's not obvious in which order each part should be written. I understand that it's something like:
Or if you prefer a shorter version:
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.
I copied the following paragraphs from the description of the print-like formatting in Python: https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting.
I think that it also can benefit from from similar changes, but let leave it to other issue.