]> granicus.if.org Git - python/commitdiff
Make bytesobject raise ValueError instead of TypeError again (thanks, Nick)
authorThomas Wouters <thomas@python.org>
Tue, 22 Aug 2006 13:41:17 +0000 (13:41 +0000)
committerThomas Wouters <thomas@python.org>
Tue, 22 Aug 2006 13:41:17 +0000 (13:41 +0000)
Lib/test/test_bytes.py
Objects/bytesobject.c

index 06beb1d00772f21a48c2a85c1865d13092ac655b..d45ff648510d9e9bc24b3946f6a45478fa0d4a3b 100644 (file)
@@ -60,13 +60,13 @@ class BytesTest(unittest.TestCase):
         self.assertRaises(ValueError, bytes, [-1])
         self.assertRaises(ValueError, bytes, [-sys.maxint])
         self.assertRaises(ValueError, bytes, [-sys.maxint-1])
-        self.assertRaises(TypeError, bytes, [-sys.maxint-2])
-        self.assertRaises(TypeError, bytes, [-10**100])
+        self.assertRaises(ValueError, bytes, [-sys.maxint-2])
+        self.assertRaises(ValueError, bytes, [-10**100])
         self.assertRaises(ValueError, bytes, [256])
         self.assertRaises(ValueError, bytes, [257])
         self.assertRaises(ValueError, bytes, [sys.maxint])
-        self.assertRaises(TypeError, bytes, [sys.maxint+1])
-        self.assertRaises(TypeError, bytes, [10**100])
+        self.assertRaises(ValueError, bytes, [sys.maxint+1])
+        self.assertRaises(ValueError, bytes, [10**100])
 
     def test_repr(self):
         self.assertEqual(repr(bytes()), "bytes()")
index 241281e257e3869c611f9a642631b3e5f2dbf9b8..d6cce6d49ec9cee38e3a3ae72685303cb767cb16 100644 (file)
@@ -245,7 +245,7 @@ bytes_contains(PyBytesObject *self, PyObject *value)
     if (PyBytes_Check(value))
         return bytes_substring(self, (PyBytesObject *)value);
 
-    ival = PyNumber_AsSsize_t(value, PyExc_TypeError);
+    ival = PyNumber_AsSsize_t(value, PyExc_ValueError);
     if (ival == -1 && PyErr_Occurred())
         return -1;
     if (ival < 0 || ival >= 256) {
@@ -365,7 +365,7 @@ bytes_setitem(PyBytesObject *self, Py_ssize_t i, PyObject *value)
     if (value == NULL)
         return bytes_setslice(self, i, i+1, NULL);
 
-    ival = PyNumber_AsSsize_t(value, PyExc_TypeError);
+    ival = PyNumber_AsSsize_t(value, PyExc_ValueError);
     if (ival == -1 && PyErr_Occurred())
         return -1;
 
@@ -448,7 +448,7 @@ bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
     }
 
     /* Is it an int? */
-    count = PyNumber_AsSsize_t(arg, PyExc_TypeError);
+    count = PyNumber_AsSsize_t(arg, PyExc_ValueError);
     if (count == -1 && PyErr_Occurred())
         PyErr_Clear();
     else {
@@ -500,7 +500,7 @@ bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
         }
 
         /* Interpret it as an int (__index__) */
-        value = PyNumber_AsSsize_t(item, PyExc_TypeError);
+        value = PyNumber_AsSsize_t(item, PyExc_ValueError);
         Py_DECREF(item);
         if (value == -1 && PyErr_Occurred())
             goto error;