diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 9f8f0e1..1e6ec19 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -170,6 +170,10 @@ class BoolTest(unittest.TestCase): self.assertIs(bool(""), False) self.assertIs(bool(), False) + def test_keyword_args(self): + with self.assertWarns(DeprecationWarning): + self.assertIs(bool(x=10), True) + def test_format(self): self.assertEqual("%d" % False, "0") self.assertEqual("%d" % True, "1") diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index ac8473d..91e3b7a 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -208,6 +208,10 @@ class GeneralFloatCases(unittest.TestCase): with self.assertWarns(DeprecationWarning): self.assertIs(type(FloatSubclass(F())), FloatSubclass) + def test_keyword_args(self): + with self.assertWarns(DeprecationWarning): + self.assertEqual(float(x='3.14'), 3.14) + def test_is_integer(self): self.assertFalse((1.1).is_integer()) self.assertTrue((1.).is_integer()) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index 14bbd61..db96967 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -246,9 +246,11 @@ class IntTestCases(unittest.TestCase): def test_keyword_args(self): # Test invoking int() using keyword arguments. - self.assertEqual(int(x=1.2), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(int(x=1.2), 1) self.assertEqual(int('100', base=2), 4) - self.assertEqual(int(x='100', base=2), 4) + with self.assertWarns(DeprecationWarning): + self.assertEqual(int(x='100', base=2), 4) self.assertRaises(TypeError, int, base=10) self.assertRaises(TypeError, int, base=0) diff --git a/Objects/boolobject.c b/Objects/boolobject.c index 31510bb..795112b 100644 --- a/Objects/boolobject.c +++ b/Objects/boolobject.c @@ -48,6 +48,11 @@ bool_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bool", kwlist, &x)) return NULL; + if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) { + if (PyErr_Warn(PyExc_DeprecationWarning, + "The \"x\" keyword argument of bool() is deprecated") < 0) + return NULL; + } ok = PyObject_IsTrue(x); if (ok < 0) return NULL; diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 17a55dd..5b229d5 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -1569,6 +1569,11 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return float_subtype_new(type, args, kwds); /* Wimp out */ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x)) return NULL; + if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) { + if (PyErr_Warn(PyExc_DeprecationWarning, + "The \"x\" keyword argument of float() is deprecated") < 0) + return NULL; + } /* If it's a string, but not a string subclass, use PyFloat_FromString. */ if (PyUnicode_CheckExact(x)) diff --git a/Objects/longobject.c b/Objects/longobject.c index 0bf6cee..2f50934 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4811,6 +4811,11 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } return PyLong_FromLong(0L); } + if (PyTuple_GET_SIZE(args) == 0) { + if (PyErr_Warn(PyExc_DeprecationWarning, + "The \"x\" keyword argument of int() is deprecated") < 0) + return NULL; + } if (obase == NULL) return PyNumber_Long(x);