New submission from Thomas Lee:

Initial patch attached.

----------
components: Interpreter Core
files: bytes-unicode-return-false-r1.patch
messages: 56284
nosy: thomas.lee
severity: normal
status: open
title: PEP 3137 patch: make PyBytes/PyUnicode ==/!= comparisons return False
type: rfe
versions: Python 3.0

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1249>
__________________________________
Index: Objects/bytesobject.c
===================================================================
--- Objects/bytesobject.c	(revision 58387)
+++ Objects/bytesobject.c	(working copy)
@@ -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_False);
+            return Py_False;
     }
 
     self_size = _getbuffer(self, &self_bytes);
Index: Lib/test/test_bytes.py
===================================================================
--- Lib/test/test_bytes.py	(revision 58387)
+++ Lib/test/test_bytes.py	(working copy)
@@ -132,10 +132,10 @@
 
         # Bytes can't be compared to Unicode!
         # 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)
 
     def test_nohash(self):
         self.assertRaises(TypeError, hash, bytes())
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to