[Python-ideas] a new bytestring type?

Nick Coghlan ncoghlan at gmail.com
Sun Jan 5 23:57:24 CET 2014


On 6 Jan 2014 03:56, "Ethan Furman" <ethan at stoneleaf.us> wrote:
>
> As anyone who has worked with Python 3 and low-level protocols knows,
Python 3 has no 'bytestring' type.  It has immutable and mutable versions
of arrays of integers, otherwise known as 'bytes' and 'bytearray'.
>
> How many would be interested in having a 'bytestring'?
>
> What do you see as the distinguishing characteristics?

I actually expected someone to have experimented with an "encodedstr" type
by now. This would be a type that behaved like the Python 2 str type, but
had an encoding attribute. On encountering Unicode text strings, it would
encode then appropriately.

However, people have generally instead followed the model of decoding to
text and operating in that domain, since it avoids a lot of subtle issues
(like accidentally embedding byte order marks when concatenating strings).

This is likely encouraged by the fact that str, bytes and bytearray don't
currently implement type coercion correctly (which in turn is due to a long
standing bug in the way the abstract C API handles sequence types defined
in C rather than Python), so an encodedstr type would need to inherit from
str or bytes to get interoperability, and then wouldn't interoperate with
the other one.

Cheers,
Nick.

>
> --
> ~Ethan~
> _______________________________________________
> 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/20140106/db7986b5/attachment.html>


More information about the Python-ideas mailing list