diff Objects/stringobject.c @ 24415:f5cfa0ee02cf legacy-trunk

Fix the problem of not raising a TypeError exception when doing: '%g' % '1' '%d' % '1' Add a test for these conditions Fix the test so that if not exception is raise, this is a failure
author Neal Norwitz <nnorwitz@gmail.com>
date Sun, 28 Jul 2002 16:44:23 +0000
parents d6ec4dab927e
children b25c31e008c8
line wrap: on
line diff
--- a/Objects/stringobject.c	Sun Jul 28 16:35:57 2002 +0000
+++ b/Objects/stringobject.c	Sun Jul 28 16:44:23 2002 +0000
@@ -3120,11 +3120,11 @@
 	   worst case length = 3 + 10 (len of INT_MAX) + 1 = 14 (use 20)*/
 	char fmt[20];
 	double x;
-	v = PyNumber_Float(v);
-	if (!v)
+	x = PyFloat_AsDouble(v);
+	if (x == -1.0 && PyErr_Occurred()) {
+		PyErr_SetString(PyExc_TypeError, "float argument required");
 		return -1;
-	x = PyFloat_AS_DOUBLE(v);
-	Py_DECREF(v);
+	}
 	if (prec < 0)
 		prec = 6;
 	if (type == 'f' && fabs(x)/1e25 >= 1e25)
@@ -3299,11 +3299,11 @@
 	char fmt[64];	/* plenty big enough! */
 	long x;
 
-	v = PyNumber_Int(v);
-	if (!v)
+	x = PyInt_AsLong(v);
+	if (x == -1 && PyErr_Occurred()) {
+		PyErr_SetString(PyExc_TypeError, "int argument required");
 		return -1;
-	x = PyInt_AS_LONG(v);
-	Py_DECREF(v);
+	}
 	if (prec < 0)
 		prec = 1;