[Python-3000-checkins] r51472 - in python/branches/p3yk: Lib/test/test_bytes.py Objects/bytesobject.c

thomas.wouters python-3000-checkins at python.org
Tue Aug 22 15:41:17 CEST 2006


Author: thomas.wouters
Date: Tue Aug 22 15:41:17 2006
New Revision: 51472

Modified:
   python/branches/p3yk/Lib/test/test_bytes.py
   python/branches/p3yk/Objects/bytesobject.c
Log:

Make bytesobject raise ValueError instead of TypeError again (thanks, Nick)



Modified: python/branches/p3yk/Lib/test/test_bytes.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_bytes.py	(original)
+++ python/branches/p3yk/Lib/test/test_bytes.py	Tue Aug 22 15:41:17 2006
@@ -60,13 +60,13 @@
         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()")

Modified: python/branches/p3yk/Objects/bytesobject.c
==============================================================================
--- python/branches/p3yk/Objects/bytesobject.c	(original)
+++ python/branches/p3yk/Objects/bytesobject.c	Tue Aug 22 15:41:17 2006
@@ -245,7 +245,7 @@
     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 @@
     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 @@
     }
 
     /* 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 @@
         }
 
         /* 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;


More information about the Python-3000-checkins mailing list