[issue28307] Accelerate 'string' % (value, ...) by using formatted string literals

Serhiy Storchaka report at bugs.python.org
Sun May 16 07:50:56 EDT 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

PR 26160 adds support of %d, %i, %u, %o, %x, %X, %f, %e, %g, %F, %E, %G.

What is not supported:

* Formatting with a single value not wrapped into a 1-tuple (like in "%d bytes" % size). The behavior is non-trivial, it needs checking whether the value is a tuple or a mapping. It would require adding more opcodes and AST nodes and generating complex bytecode.
* Mapping keys (like in "%(name)s"). They are rarely used, and if used, it is not performance critical.
* Precision for integer formatting. Precision is not supported in new-style formatting of integers, and it is not trivial to reproduce this behavior.
* Variable width and precision (like in "%*.*s"). It is possible to support them, but the code would be pretty complex, and the benefit is small, because this feature is rarely used and is not performance critical.
* Format code %c. It is relatively rarely used.
* Length modifiers "h", "l" and "L" (like in "%ld"). They ignored in Python and I did not see them in real code. While supporting them is easy, it would requires adding more than one line of code, it is not worth it.

----------
priority: low -> normal

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue28307>
_______________________________________


More information about the Python-bugs-list mailing list