STINNER Victor added the comment:
I implemented overkill optimization in _PyUnicodeWriter API used by
str.format() and str%args. If the result is the input, the string is not copied
by value, but by reference.
>>> x="hello"
>>> ("%s" % x) is x
True
>>> ("{}".format(x)) is x
True
If the format string adds something before/after, the string is duplicated:
>>> ("x=%s" % x) is x
False
>>> ("x={}".format(x)) is x
False
The optimization is implemented in _PyUnicodeWriter_WriteStr():
https://hg.python.org/cpython/file/32a4e7b337c9/Objects/unicodeobject.c#l13604
----------
nosy: +haypo
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue26118>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com