On Sun, Nov 03, 2019 at 11:31:22AM +0100, Anders Hovmöller wrote: > > Given: > > > > values = ["Hello", b"World"] > > > > would you expect ' '.join(values) to return > > > > "Hello b'World'" > > > > because that's what you'll get calling str automatically. > > Side note! > > That misfeature of python 3 was one of the largest source of > continuing bugs in production for us after we switched.
Misfeature? If you called it a "gotcha", I'd agree with your description. We have two mutually exclusive requirements: 1. You should be able to coerce *anything* and *everything* into a string, no exceptions. Round tripping is not required, but print(x) should never fail, it should always print something, and that requires that str(x) should work for all x. 2. We shouldn't be able to turn bytes into a str without specifying the correct encoding to use. Clearly we can't have both requirements, we have to choose one or the other. The compromise solution was to change requirement 2 to be something like: 2a. We shouldn't be able to DECODE bytes into a str without specifying the correct encoding to use (using the decode method). and allow str(bytes) with no encoding specified to just return a representation of the bytes object. Like all compromises, nobody is really happy about it, but some people are probably more unhappy than others. While I sympathise with your pain, its hard to see that any other solution would have been better. -- Steven _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/T4UAMFHZQ65UE63GQWDC63PCKZG6PNBE/ Code of Conduct: http://python.org/psf/codeofconduct/