[issue26555] string.format(bytes) raise warning

2016-03-14 Thread STINNER Victor
STINNER Victor added the comment: > Well, it's not what format() is doing now, using str()? :) Hum, are you sure that you tried Python 3, and not Python 2? str(bytes) on Python 3 is well defined: >>> print(str(b'hello')) b'hello' >>> print(str('h\xe9llo'.encode('utf8'))) b'h\xc3\xa9llo' I'm n

[issue26555] string.format(bytes) raise warning

2016-03-14 Thread Marco Sulla
Marco Sulla added the comment: > Using utf8 means guessing the encoding Well, it's not what format() is doing now, using str()? :) -- ___ Python tracker ___

[issue26555] string.format(bytes) raise warning

2016-03-14 Thread STINNER Victor
STINNER Victor added the comment: >> Python 3 doesn't guess the encoding of byte strings anymore > And I agree, but I think format minilanguage could convert it by default to > utf8, .. Using utf8 means guessing the encoding of a byte string. Python 3 doesn't do that anymore, there is no more

[issue26555] string.format(bytes) raise warning

2016-03-14 Thread Marco Sulla
Marco Sulla added the comment: > Python 3 doesn't guess the encoding of byte strings anymore And I agree, but I think format minilanguage could convert it by default to utf8, and if something goes wrong raise an error (or try str()). More simple to use and robust at the same time. My 2 cents.

[issue26555] string.format(bytes) raise warning

2016-03-14 Thread STINNER Victor
STINNER Victor added the comment: More about Unicode: * https://docs.python.org/dev/howto/unicode.html * http://unicodebook.readthedocs.org/ * etc. -- ___ Python tracker ___ ___

[issue26555] string.format(bytes) raise warning

2016-03-14 Thread STINNER Victor
STINNER Victor added the comment: > I would that the format minilanguage will convert bytes to string properly. Sorry, nope, Python 3 doesn't guess the encoding of byte strings anymore. You have to decode manually. Example: "Hello {}".format(b"World".decode('ascii')) Or format to bytes: b"He

[issue26555] string.format(bytes) raise warning

2016-03-14 Thread Marco Sulla
Marco Sulla added the comment: I want to clarify more: I do not want to suppress the warning, I would that the format minilanguage will convert bytes to string properly. -- ___ Python tracker _

[issue26555] string.format(bytes) raise warning

2016-03-14 Thread Marco Sulla
New submission from Marco Sulla: Steps to reproduce 1. create a format_bytes.py with: "Hello {}".format(b"World") 2. launch it with python3 -bb format_bytes.py Result: Traceback (most recent call last): File "format_bytes.py", line 1, in "Hello {}".format(b"World") BytesWarning: str()