Guido van Rossum added the comment:
It would be unacceptable if print(b) were to raise an exception. The reason the
transitional period is long is just that people are still porting Python 2 code.
--
assignee: -> gvanrossum
status: pending -> closed
___
Antoine Pitrou added the comment:
> I'm not sure what the "transitional period" refers to, though.
The Python 2 -> Python 3 migration.
> It's 8 years later now and doesn't look like str(bytes_object) will
go away a source of subtle bugs anytime soon
str(bytes_object) is perfectly reasonable wh
R. David Murray added the comment:
Yeah, that's why I run tests with -bb myself. Except that there was a bug in
-W/-bb handling that meant I wasn't really...and that bit me because there is
at least one buildbot that really does, and it complained...
(Although in that case the 'bug' was reall
Marc-Andre Lemburg added the comment:
On 22.04.2015 15:52, R. David Murray wrote:
> str accepting bytes and returning the repr was a conscious design choice, as
> evidenced by the -bb option, and I'm sure there is code that is both
> unintentionally and *intentionally* using this, despite the w
R. David Murray added the comment:
str accepting bytes and returning the repr was a conscious design choice, as
evidenced by the -bb option, and I'm sure there is code that is both
unintentionally and *intentionally* using this, despite the warning. Unless we
want to discuss making the -bb be
Serhiy Storchaka added the comment:
In Python 2, the unicode() constructor accepts bytes argument if it is
decodeable with sys.getdefaultencoding().
>>> unicode(b'abc')
u'abc'
>>> import sys
>>> reload(sys)
>>> sys.setdefaultencoding("utf-8")
>>> unicode(u'abcäöü'.encode('utf-8'))
u'abc\xe4\xf
eryksun added the comment:
bytes.__str__ can already raise either a warning (-b)
>>> str('abcäöü'.encode('utf-8'))
__main__:1: BytesWarning: str() on a bytes instance
"b'abc\\xc3\\xa4\\xc3\\xb6\\xc3\\xbc'"
or error (-bb), which applies equally to implicit conversion by print():
New submission from Marc-Andre Lemburg:
In Python 2, the unicode() constructor does not accept bytes arguments, unless
an encoding argument is given:
>>> unicode(u'abcäöü'.encode('utf-8'))
Traceback (most recent call last):
File "", line 1, in
UnicodeDecodeError: 'ascii' codec can't decode b