]> granicus.if.org Git - python/commitdiff
Issue #1680159: unicode coercion during an 'in' operation was masking
authorR. David Murray <rdmurray@bitdance.com>
Mon, 14 Dec 2009 16:28:26 +0000 (16:28 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Mon, 14 Dec 2009 16:28:26 +0000 (16:28 +0000)
any errors that might occur during coercion of the left operand and
turning them into a TypeError with a message text that was confusing in
the given context.  This patch lets any errors through, as was already
done during coercion of the right hand side.

Lib/test/test_unicode.py
Misc/NEWS
Objects/unicodeobject.c

index 2b269cc6223f59937e8ab35696ff7c7bb2b829c7..31bceb3c9fd4f7d2a46d5287b8aa5c1094db64ef 100644 (file)
@@ -344,7 +344,8 @@ class UnicodeTest(
         # If the following fails either
         # the contains operator does not propagate UnicodeErrors or
         # someone has changed the default encoding
-        self.assertRaises(UnicodeError, 'g\xe2teau'.__contains__, u'\xe2')
+        self.assertRaises(UnicodeDecodeError, 'g\xe2teau'.__contains__, u'\xe2')
+        self.assertRaises(UnicodeDecodeError, u'g\xe2teau'.__contains__, '\xe2')
 
         self.assertTrue(u'' in '')
         self.assertTrue('' in u'')
@@ -375,6 +376,7 @@ class UnicodeTest(
         self.assertTrue(u'asdf' not in u'')
 
         self.assertRaises(TypeError, u"abc".__contains__)
+        self.assertRaises(TypeError, u"abc".__contains__, object())
 
     def test_formatting(self):
         string_tests.MixinStrUnicodeUserStringTest.test_formatting(self)
index cfdf975e20f5fb37c7a57cbad1f49f66cf8d1494..08369a2e783dc998a719db97da726526fb8dcd84 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 2?
 Core and Builtins
 -----------------
 
+- Issue #1680159: unicode coercion during an 'in' operation no longer masks
+  the underlying error when the coercion fails for the left hand operand.
+
 - Issue #7491: Metaclass's __cmp__ method was ignored.
 
 - Issue #7466: segmentation fault when the garbage collector is called
index e85b20fa031686c11c82be7b397488cdbafca654..79e824ee7641dcd0106f81952e6a6110a0fe70d6 100644 (file)
@@ -6502,8 +6502,6 @@ int PyUnicode_Contains(PyObject *container,
     /* Coerce the two arguments */
     sub = PyUnicode_FromObject(element);
     if (!sub) {
-        PyErr_SetString(PyExc_TypeError,
-                        "'in <string>' requires string as left operand");
         return -1;
     }