[Python-ideas] Stop displaying elements of bytes objects as printable ASCII characters in CPython 3

Nick Coghlan ncoghlan at gmail.com
Thu Sep 11 08:58:51 CEST 2014


On 11 September 2014 16:47, Chris Lasher <chris.lasher at gmail.com> wrote:
> You passed bytes – not an ASCII string – as an argument to os.listdir; it
> gave you back bytes, not ASCII strings. You _consented_ to bytes when you
> put the b'Mac' in there; therefore, you are responsible for decoding those
> bytes.
>
>
> Yes, all text must be represented an bytes to a computer, but not all bytes
> represent text.

Yes, we know. We debated this 8 years ago. We *tried it* 8 years ago.
We found it to provide a horrible developer experience, so we changed
it back to be closer to the way Python 2 works. Changing the default
representation of binary data to something that we already decided
didn't work (or at least its very close cousin) is not up for
discussion.

Providing better tools for easily producing hexadecimal
representations is an excellent idea. Making developers explicitly
request non-horrible output when working with binary APIs on POSIX
systems is not.

You can keep saying "but it's potentially confusing when it really is
arbitrary binary data", and I'm telling you *that doesn't matter*. The
consequences of flipping the default are worse, because it means
defaulting to unreadable output from supported operating system
interfaces, which *will* leak through to API consumers and potentially
even end users. That's not OK, which means the status quo is the
lesser of two evils.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list