bpo-29793: Convert some builtin types constructors to Argument Clinic. (#615)
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 8f87f8e..86c3c88 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1612,19 +1612,23 @@
}
static PyObject *
-float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
+float_subtype_new(PyTypeObject *type, PyObject *x);
+
+/*[clinic input]
+@classmethod
+float.__new__ as float_new
+ x: object(c_default="Py_False") = 0
+ /
+
+Convert a string or number to a floating point number, if possible.
+[clinic start generated code]*/
static PyObject *
-float_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+float_new_impl(PyTypeObject *type, PyObject *x)
+/*[clinic end generated code: output=ccf1e8dc460ba6ba input=c98d8e811ad2037a]*/
{
- PyObject *x = Py_False; /* Integer zero */
-
if (type != &PyFloat_Type)
- return float_subtype_new(type, args, kwds); /* Wimp out */
- if (!_PyArg_NoKeywords("float()", kwds))
- return NULL;
- if (!PyArg_UnpackTuple(args, "float", 0, 1, &x))
- return NULL;
+ return float_subtype_new(type, x); /* Wimp out */
/* If it's a string, but not a string subclass, use
PyFloat_FromString. */
if (PyUnicode_CheckExact(x))
@@ -1638,12 +1642,12 @@
from the regular float. The regular float is then thrown away.
*/
static PyObject *
-float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+float_subtype_new(PyTypeObject *type, PyObject *x)
{
PyObject *tmp, *newobj;
assert(PyType_IsSubtype(type, &PyFloat_Type));
- tmp = float_new(&PyFloat_Type, args, kwds);
+ tmp = float_new_impl(&PyFloat_Type, x);
if (tmp == NULL)
return NULL;
assert(PyFloat_Check(tmp));
@@ -1874,11 +1878,6 @@
{NULL} /* Sentinel */
};
-PyDoc_STRVAR(float_doc,
-"float(x) -> floating point number\n\
-\n\
-Convert a string or number to a floating point number, if possible.");
-
static PyNumberMethods float_as_number = {
float_add, /* nb_add */
@@ -1937,7 +1936,7 @@
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- float_doc, /* tp_doc */
+ float_new__doc__, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
float_richcompare, /* tp_richcompare */