On Mon, 13 Jan 2014 08:36:05 -0800
Ethan Furman <et...@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 <gu...@python.org> wrote:
> >> On Mon, Jan 13, 2014 at 3:41 AM, Antoine Pitrou <solip...@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.

No, there's a good reason for the str case: it's that every Python
object should have a working __str__ (for debugging, REPL use, etc.).
So bytes has a __str__ too and that's why "%s" % (some_bytes_object)
succeeds.

Conversely, though, str needn't and shouldn't have a __bytes__, so
there's no good reason for b"%s" % (some_str_object) to succeed.

(moreover, I don't think "we did it wrong here" should be a good reason
for doing it wrong there too)

Regards

Antoine.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to