[Python-3000-checkins] r66950 - in python/branches/py3k: Lib/test/test_bytes.py Objects/bytearrayobject.c Objects/bytesobject.c

barry.warsaw python-3000-checkins at python.org
Fri Oct 17 03:50:38 CEST 2008


Author: barry.warsaw
Date: Fri Oct 17 03:50:37 2008
New Revision: 66950

Log:
STINNER Victor (haypo)'s patch for bug 3988, Byte warning mode and b'' != ''

Also, his patch to runtests.sh to pass the -bb option (issue 4125).


Modified:
   python/branches/py3k/Lib/test/test_bytes.py
   python/branches/py3k/Objects/bytearrayobject.c
   python/branches/py3k/Objects/bytesobject.c

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	Fri Oct 17 03:50:37 2008
@@ -9,6 +9,7 @@
 import re
 import sys
 import copy
+import operator
 import pickle
 import tempfile
 import unittest
@@ -863,6 +864,17 @@
         b = bytearray()
         self.failIf(b.replace(b'', b'') is b)
 
+    def test_compare(self):
+        if sys.flags.bytes_warning:
+            warnings.simplefilter('error', BytesWarning)
+            self.assertRaises(BytesWarning, operator.eq, b'', '')
+            self.assertRaises(BytesWarning, operator.ne, b'', '')
+            self.assertRaises(BytesWarning, operator.eq, bytearray(b''), '')
+            self.assertRaises(BytesWarning, operator.ne, bytearray(b''), '')
+        else:
+            # raise test.support.TestSkipped("BytesWarning is needed for this test: use -bb option")
+            pass
+
     # Optimizations:
     # __iter__? (optimization)
     # __reversed__? (optimization)

Modified: python/branches/py3k/Objects/bytearrayobject.c
==============================================================================
--- python/branches/py3k/Objects/bytearrayobject.c	(original)
+++ python/branches/py3k/Objects/bytearrayobject.c	Fri Oct 17 03:50:37 2008
@@ -939,7 +939,7 @@
        error, even if the comparison is for equality. */
     if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) ||
         PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) {
-        if (Py_BytesWarningFlag && op == Py_EQ) {
+        if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE)) {
             if (PyErr_WarnEx(PyExc_BytesWarning,
                             "Comparison between bytearray and string", 1))
                 return NULL;

Modified: python/branches/py3k/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k/Objects/bytesobject.c	(original)
+++ python/branches/py3k/Objects/bytesobject.c	Fri Oct 17 03:50:37 2008
@@ -818,7 +818,7 @@
 
 	/* Make sure both arguments are strings. */
 	if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
-		if (Py_BytesWarningFlag && (op == Py_EQ) &&
+		if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE) &&
 		    (PyObject_IsInstance((PyObject*)a,
 					 (PyObject*)&PyUnicode_Type) ||
 		    PyObject_IsInstance((PyObject*)b,


More information about the Python-3000-checkins mailing list