[New-bugs-announce] [issue4328] "à" in u"foo" raises a misleading error
Ezio Melotti
report at bugs.python.org
Sat Nov 15 10:27:24 CET 2008
New submission from Ezio Melotti <ezio.melotti at gmail.com>:
With Python 2.x:
>>> 'à' in u'foo'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'in <string>' requires string as left operand
>>> 'à' in u'xàx'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'in <string>' requires string as left operand
The error claims that "'in <string>' requires string as left operand"
when actually the left operand *is* a string.
With Python2.6 with unicode_literals:
>>> print(b'\x85')
à
>>> b'\x85' in 'foo'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand
With Python3.x the error is slightly different:
TypeError: 'in <string>' requires string as left operand, not bytes
but then it works with:
>>> b'f' in 'foo'
True
This problem seems somehow related to the implicit decoding of 'à'. I
guess that 'à' in u'foo' should raise a UnicodeDecodeError ('xxx' codec
can't decode byte 0x85 ...), not a TypeError.
----------
components: Unicode
messages: 75907
nosy: ezio.melotti
severity: normal
status: open
title: "à" in u"foo" raises a misleading error
versions: Python 2.4, Python 2.5, Python 2.5.3, Python 2.6, Python 3.0
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4328>
_______________________________________
More information about the New-bugs-announce
mailing list