[issue21401] python2 -3 does not warn about str/unicode to bytes conversions and comparisons

Joshua J Cogliati report at bugs.python.org
Thu May 1 17:14:12 CEST 2014


Joshua J Cogliati added the comment:

Hm.  That is a good point.  Possibly it could only be done when 
from __future__ import unicode_literals
has been used.  For example:

python2 -3
Python 2.7.5 <snip>
Type "help", "copyright", "credits" or "license" for more information.
>>> type(b"a") == type("a")
True
>>> from __future__ import unicode_literals
>>> type(b"a") == type("a")
False
>>> b"a" == "a"
True
>>> b"a" + "a"
u'aa'
>>> 


After unicode_literals is used, then b"a" and "a" have a different type and the same code would be an issue in python3:
 python3
Python 3.3.2 <snip>
>>> type(b"a") == type("a")
False
>>> b"a" == "a"
False
>>> b"a" + "a"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't concat bytes to str
>>>

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21401>
_______________________________________


More information about the Python-bugs-list mailing list