This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients ezio.melotti
Date 2008-11-15.09:27:21
SpamBayes Score 4.1738835e-11
Marked as misclassified No
Message-id <1226741244.61.0.833545368302.issue4328@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008-11-15 09:27:24ezio.melottisetrecipients: + ezio.melotti
2008-11-15 09:27:24ezio.melottisetmessageid: <1226741244.61.0.833545368302.issue4328@psf.upfronthosting.co.za>
2008-11-15 09:27:22ezio.melottilinkissue4328 messages
2008-11-15 09:27:21ezio.melotticreate