[Python-Dev] PEP 460 reboot
solipsis at pitrou.net
Mon Jan 13 18:31:14 CET 2014
On Mon, 13 Jan 2014 08:36:05 -0800
Ethan Furman <ethan at stoneleaf.us> wrote:
> On 01/13/2014 08:09 AM, Antoine Pitrou wrote:
> > On Mon, 13 Jan 2014 07:59:10 -0800
> > Guido van Rossum <guido at python.org> wrote:
> >> On Mon, Jan 13, 2014 at 3:41 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> >>> What is the use case for embedding a quoted ASCII-encoded representation
> >>> in a byte stream?
> >> It doesn't crash but produces undesired output (always, not only when
> >> the data is non-ASCII) that gives the developer a hint to think about
> >> encoding to bytes.
> > But why is it better to give a hint by producing undesired output (which
> > may actually go unnoticed for some time and produce issues down the
> > road), rather than simply by raising TypeError?
> You mean crash all the time? I'd be fine with that for both the str case
> and the bytes case. But's probably too late
> to change the str case, and the bytes case should mirror what str does.
Let me add something else: str and bytes don't have to be symmetrical.
In Python 2, str and unicode were symmetrical, they allowed exactly the
same operations and were composable.
In Python 3, str and bytes are different beasts; they have different
operations *and* different semantics (for example, bytes interoperates
with bytearray and memoryview, while str doesn't).
So bytes formatting really needn't (and shouldn't, IMO) mirror str
(the only reason I used "%s" in PEP 460 is to allow a migration path
from 2.x bytes-formatting to 3.x bytes-formatting; in a really "pure"
proposal it would have been called something else)
More information about the Python-Dev