[Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?]
Nick Coghlan
ncoghlan at gmail.com
Wed Jan 8 10:59:33 CET 2014
On 8 Jan 2014 14:08, "Stephen J. Turnbull" <stephen at xemacs.org> wrote:
>
> Terry Reedy writes:
>
> > The above describes a minor variation on bytes and seems to me to be a
> > classic case for subclassing, whether in Python for ease or C for
speed,
> > in an imported module.
>
> I agree with you, but the discussion on python-dev indicates that the
> majority of core devs, including Guido IIUC, disagree with us. In
> fact they want to add many str-like capabilities to bytes (and the
> related mutable classes bytearray and memoryview).
That's far from a foregone conclusion. The main problem we've had over the
past few years is the inability to get past "just give us back the Python 2
str type" responses from wire protocol developers attempting to migrate
that aren't happy with the approach of manipulating data in the text domain
and on to actual experiments with a suitable type for wire protocol
development that interoperates nicely with the Python 3 text model.
Now that your proposal has been better explained, yes, I agree that
"asciibytes" and "asciistr" types would be well worth experimenting with. I
mention both, since it's far from clear if a str subclass or a bytes
subclass (or neither, although that may require bug fixes in CPython) would
be more convenient for this use case.
The key difference between such a type and a str with surrogate escaped
elements or a Python 2 bytestring is that it would attempt to implicitly
*encode* any Unicode text it encountered as strict ASCII text. This would
allow text and binary processing to share code paths, with limited risk of
producing mojibake (particularly since this type wouldn't be a builtin).
The type would also share the str behaviour of returning a single element
subsequence when indexed rather than an integer.
Cheers,
Nick.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140108/8ad96a74/attachment.html>
More information about the Python-ideas
mailing list