diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-01-01 17:27:30 +0000 |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-01-01 17:27:30 +0000 |
commit | 1b34d2552c2cb2369130291a8a9ae973753b4072 (patch) | |
tree | 5bfcf8b49745280e0a92a49ef2102d81c3674b68 /Python/getargs.c | |
parent | edfe72f66fd789d65b0c7125540c08d3e98a901e (diff) | |
download | cpython-git-1b34d2552c2cb2369130291a8a9ae973753b4072.tar.gz |
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.
Diffstat (limited to 'Python/getargs.c')
-rw-r--r-- | Python/getargs.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 1fd17d3ddc..287b5d9be8 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -526,7 +526,7 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize) /* 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 @@ float_argument_error(PyObject *arg) 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 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, #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 { |