-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Extend PyUnicode_FromFormat() #98836
Labels
Comments
serhiy-storchaka
added
type-feature
A feature request or enhancement
topic-unicode
topic-C-API
labels
Oct 29, 2022
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Oct 29, 2022
* 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).
I am not sure that it is worth support I am ready to discuss inclusion or exclusion of other formatting features. |
serhiy-storchaka
added a commit
that referenced
this issue
May 21, 2023
* 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).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PyUnicode_FromFormat()
and several other functions likePyErr_Format()
support a subset of printf-like formatting with some extensions to support Python objects. It is a very limited subset, for example%x
is supported, but%lx
and%X
are not.I propose to add support of more printf features:
o
(octal) andX
(uppercase hexadecimal).j
(intmax_t) andt
(ptrdiff_t).%ls
and%lV
).*
.-
(left alignment).The following standard features are intentionally not implemented:
#
,+
.#
is ambiguous for octals: should we use prefix0
(as in C) or0o
(as in Python)? The latter two flags are just rarely used (I initially implemented the support of them, but then removed, it is not worth).h
(signed char
andunsigned char
) andhh
(short
andunsigned short
). Values of these types are automatically promoted toint
orunsigned int
, and you can use explicit conversion toint
orunsigned int
in case of ambiguity.%lc
. Since%c
already accepts integers outside of the range 0-255, and the difference betweenint
andwint_t
is subtle, I am not sure that that there is any value of supporting it.%n
.%c
and%p
.Unlike to printf, unsupported modifiers (like
%lc
or%10c
) raise SystemError instead of be silently ignored. It will allow to add new features without breaking accidentally working code.The text was updated successfully, but these errors were encountered: