New submission from Ezio Melotti <[EMAIL PROTECTED]>: 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 <[EMAIL PROTECTED]> <http://bugs.python.org/issue4328> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com