Re: [Python-checkins] cpython: Implement PEP 393.
Martin v. Löwis <martin <at> v.loewis.de>
2011-10-01 13:26:01 GMT
Am 29.09.2011 01:21, schrieb Eric V. Smith:
> Is there some reason str.format had such major surgery done to it?
Yes: I couldn't figure out how to do it any other way. The formatting
code had a few basic assumptions which now break (unless you keep using
the legacy API). Primarily, the assumption is that there is a notion of
a "STRINGLIB_CHAR" which is the element of a string representation. With
PEP 393, no such type exists anymore - it depends on the individual
object what the element type for the representation is.
In other cases, I worked around that by compiling the stringlib three
times, for Py_UCS1, Py_UCS2, and Py_UCS4. For one, this gives
considerable code bloat, which I didn't like for the formatting code
(as that is already a considerable amount of code). More importantly,
this approach wouldn't have worked well, anyway, since the formatting
combines multiple Unicode objects (especially with the OutputString
buffer), and different inputs may have different representations. On
top of that, OutputString needs widening support, starting out with
a narrow string, and widening step-by-step as input strings are more
wide than the current output (or not, if the input strings are all
It would have been possible to keep the basic structure by doing
all formatting in Py_UCS4. This would cost a significant memory and
> In addition, there are outstanding patches that are now broken.
I'm sorry about that. Try applying them to the new files, though - patch
may still be able to figure out how to integrate them, as the