diff Python/getargs.c @ 58070:2de24bb33cc5 legacy-trunk

Issue #5080: turn the DeprecationWarning from float arguments passed to integer PyArg_Parse* format codes into a TypeError. Add a DeprecationWarning for floats passed with the 'L' format code, which didn't previously have a warning.
author Mark Dickinson <dickinsm@gmail.com>
date Fri, 01 Jan 2010 17:27:30 +0000
parents 3af3fb168638
children d11fbc796499
line wrap: on
line diff
--- a/Python/getargs.c	Fri Jan 01 15:21:13 2010 +0000
+++ b/Python/getargs.c	Fri Jan 01 17:27:30 2010 +0000
@@ -526,7 +526,7 @@
 /* explicitly check for float arguments when integers are expected.  For now
  * signal a warning.  Returns true if an exception was raised. */
 static int
-float_argument_error(PyObject *arg)
+float_argument_warning(PyObject *arg)
 {
 	if (PyFloat_Check(arg) &&
 	    PyErr_Warn(PyExc_DeprecationWarning,
@@ -536,6 +536,20 @@
 		return 0;
 }
 
+/* explicitly check for float arguments when integers are expected.  Raises
+   TypeError and returns true for float arguments. */
+static int
+float_argument_error(PyObject *arg)
+{
+	if (PyFloat_Check(arg)) {
+		PyErr_SetString(PyExc_TypeError,
+				"integer argument expected, got float");
+		return 1;
+	}
+	else
+		return 0;
+}
+
 /* Convert a non-tuple argument.  Return NULL if conversion went OK,
    or a string with a message describing the failure.  The message is
    formatted as "must be <desired type>, not <actual type>".
@@ -719,7 +733,10 @@
 #ifdef HAVE_LONG_LONG
 	case 'L': {/* PY_LONG_LONG */
 		PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * );
-		PY_LONG_LONG ival = PyLong_AsLongLong( arg );
+		PY_LONG_LONG ival;
+		if (float_argument_warning(arg))
+			return converterr("long<L>", arg, msgbuf, bufsize);
+		ival = PyLong_AsLongLong(arg);
 		if (ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) {
 			return converterr("long<L>", arg, msgbuf, bufsize);
 		} else {