Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Extend PyUnicode_FromFormat() #98836

Closed
Closed
@serhiy-storchaka

Description

@serhiy-storchaka

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:

  • Support for conversion specifierso (octal) andX (uppercase hexadecimal).
  • Support for length modifiersj (intmax_t) andt (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).

The following standard features are intentionally not implemented:

  • Support for floating point formatting. It is very rare in error messages and reprs, and you always can use sprintf to a fixed buffer.
  • Flags#, (a space) and+.# 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).
  • Length modifiersh (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.
  • Width and precision are not supported in%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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp