Author: guido.van.rossum
Date: Tue Oct  9 19:21:10 2007
New Revision: 58390

Modified:
   python/branches/py3k/Lib/test/test_bytes.py
   python/branches/py3k/Objects/bytesobject.c
Log:
Patch #1049 by Thomas Lee.

Changes comparisons between PyBytes and PyUnicode to return unequal
instead of raising TypeError.


Modified: python/branches/py3k/Lib/test/test_bytes.py
==============================================================================
--- python/branches/py3k/Lib/test/test_bytes.py (original)
+++ python/branches/py3k/Lib/test/test_bytes.py Tue Oct  9 19:21:10 2007
@@ -130,12 +130,14 @@
         self.assertEqual(str8("abc") < b"ab", False)
         self.assertEqual(str8("abc") <= b"ab", False)
 
-        # Bytes can't be compared to Unicode!
+        # Byte comparisons with unicode should always fail!
         # Test this for all expected byte orders and Unicode character sizes
-        self.assertRaises(TypeError, lambda: b"\0a\0b\0c" == "abc")
-        self.assertRaises(TypeError, lambda: b"\0\0\0a\0\0\0b\0\0\0c" == "abc")
-        self.assertRaises(TypeError, lambda: b"a\0b\0c\0" == "abc")
-        self.assertRaises(TypeError, lambda: b"a\0\0\0b\0\0\0c\0\0\0" == "abc")
+        self.assertEqual(b"\0a\0b\0c" == "abc", False)
+        self.assertEqual(b"\0\0\0a\0\0\0b\0\0\0c" == "abc", False)
+        self.assertEqual(b"a\0b\0c\0" == "abc", False)
+        self.assertEqual(b"a\0\0\0b\0\0\0c\0\0\0" == "abc", False)
+        self.assertEqual(bytes() == str(), False)
+        self.assertEqual(bytes() != str(), True)
 
     def test_nohash(self):
         self.assertRaises(TypeError, hash, bytes())

Modified: python/branches/py3k/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k/Objects/bytesobject.c  (original)
+++ python/branches/py3k/Objects/bytesobject.c  Tue Oct  9 19:21:10 2007
@@ -964,8 +964,8 @@
        error, even if the comparison is for equality. */
     if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) ||
         PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) {
-            PyErr_SetString(PyExc_TypeError, "can't compare bytes and str");
-            return NULL;
+        Py_INCREF(Py_NotImplemented);
+        return Py_NotImplemented;
     }
 
     self_size = _getbuffer(self, &self_bytes);
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to