Commit c7301312 authored by Mark Dickinson's avatar Mark Dickinson

Issue #8950: Make PyArg_Parse* with 'L' code raise for float inputs,

instead of warning.  This makes it consistent with the other integer
codes.
parent 37296e89
import unittest import unittest
from test import support from test import support
from _testcapi import getargs_keywords from _testcapi import getargs_keywords
import warnings
""" """
> How about the following counterproposal. This also changes some of > How about the following counterproposal. This also changes some of
...@@ -190,21 +189,7 @@ class LongLong_TestCase(unittest.TestCase): ...@@ -190,21 +189,7 @@ class LongLong_TestCase(unittest.TestCase):
from _testcapi import getargs_L from _testcapi import getargs_L
# L returns 'long long', and does range checking (LLONG_MIN # L returns 'long long', and does range checking (LLONG_MIN
# ... LLONG_MAX) # ... LLONG_MAX)
with warnings.catch_warnings(): self.assertRaises(TypeError, getargs_L, 3.14)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=".*integer argument expected, got float",
module=__name__)
self.assertEqual(3, getargs_L(3.14))
with warnings.catch_warnings():
warnings.filterwarnings(
"error",
category=DeprecationWarning,
message=".*integer argument expected, got float",
module="unittest")
self.assertRaises(DeprecationWarning, getargs_L, 3.14)
self.assertRaises(TypeError, getargs_L, "Hello") self.assertRaises(TypeError, getargs_L, "Hello")
self.assertEqual(99, getargs_L(Int())) self.assertEqual(99, getargs_L(Int()))
......
...@@ -12,6 +12,11 @@ What's New in Python 3.2 Alpha 1? ...@@ -12,6 +12,11 @@ What's New in Python 3.2 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #8950: (See also issue #5080). Py_ArgParse*() functions now
raise TypeError instead of giving a DeprecationWarning when a float
is parsed using the 'L' code (for long long). (All other integer
codes already raise TypeError in this case.)
- Issue #8922: Normalize the encoding name in PyUnicode_AsEncodedString() to - Issue #8922: Normalize the encoding name in PyUnicode_AsEncodedString() to
enable shortcuts for upper case encoding name. Add also a shortcut for enable shortcuts for upper case encoding name. Add also a shortcut for
"iso-8859-1" in PyUnicode_AsEncodedString() and PyUnicode_Decode(). "iso-8859-1" in PyUnicode_AsEncodedString() and PyUnicode_Decode().
......
...@@ -582,19 +582,6 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize) ...@@ -582,19 +582,6 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
#define CONV_UNICODE "(unicode conversion error)" #define CONV_UNICODE "(unicode conversion error)"
/* 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_warning(PyObject *arg)
{
if (PyFloat_Check(arg) &&
PyErr_Warn(PyExc_DeprecationWarning,
"integer argument expected, got float" ))
return 1;
else
return 0;
}
/* Explicitly check for float arguments when integers are expected. /* Explicitly check for float arguments when integers are expected.
Return 1 for error, 0 if ok. */ Return 1 for error, 0 if ok. */
static int static int
...@@ -791,14 +778,13 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, ...@@ -791,14 +778,13 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'L': {/* PY_LONG_LONG */ case 'L': {/* PY_LONG_LONG */
PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * ); PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * );
PY_LONG_LONG ival; PY_LONG_LONG ival;
if (float_argument_warning(arg)) if (float_argument_error(arg))
return converterr("long<L>", arg, msgbuf, bufsize); return converterr("long<L>", arg, msgbuf, bufsize);
ival = PyLong_AsLongLong(arg); ival = PyLong_AsLongLong(arg);
if (ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) { if (ival == (PY_LONG_LONG)-1 && PyErr_Occurred())
return converterr("long<L>", arg, msgbuf, bufsize); return converterr("long<L>", arg, msgbuf, bufsize);
} else { else
*p = ival; *p = ival;
}
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment