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.

classification
Title: Misleading exception from unicode.__contains__
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: lemburg Nosy List: bulbjh, lemburg, r.david.murray
Priority: normal Keywords: patch

Created on 2007-03-13 20:33 by bulbjh, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Issue1680159.patch r.david.murray, 2009-04-04 04:23 test and patch
Messages (3)
msg31513 - (view) Author: Jan Hudec (bulbjh) Date: 2007-03-13 20:33
Hello Folks,

unicode.__contains__ throws:

>>> '\xff' in u'foo'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand

while:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

would be more helpful, because that's what really fails there. The exception it throws now does not indicate that unicode is involved.

(tried this with 2.4.4 and 2.5.0 and happens in both)
msg85370 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-04-04 04:23
Still gives the same message in 2.7a0.  Looks to be simple enough to
fix: just stop masking the UnicodeDecode and TypeError messages produced
by the PyUnicode_FromObject call in the PyUnicode_Contains method.  Test
and patch attached.  If you have no objection, Mark, I'll apply it.
msg96381 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-12-14 16:29
Committed in r76831.  (I changed the test assertion to check
specifically for UnicodeDecodeError.)
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44711
2009-12-30 15:33:10r.david.murraylinkissue4328 superseder
2009-12-14 18:13:19r.david.murraysetstatus: open -> closed
stage: commit review -> resolved
resolution: fixed
versions: - Python 2.6
2009-12-14 16:29:28r.david.murraysetmessages: + msg96381
2009-04-04 04:23:54r.david.murraysetfiles: + Issue1680159.patch

type: behavior
components: + Interpreter Core, - Unicode
versions: + Python 2.6, Python 2.7
keywords: + patch
nosy: + r.david.murray

messages: + msg85370
stage: commit review
2007-03-13 20:33:15bulbjhcreate