diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-19 06:51:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-19 06:51:07 (GMT) |
commit | 18b250f844bf8b2d1a81c2d2dcc74e850364fe35 (patch) | |
tree | 117c9240b5b87067a07cb43bc9260ed26c3148bb /Objects/floatobject.c | |
parent | 0b5615926a573c19c887a701a2f7047f4fd06de6 (diff) | |
download | cpython-18b250f844bf8b2d1a81c2d2dcc74e850364fe35.zip cpython-18b250f844bf8b2d1a81c2d2dcc74e850364fe35.tar.gz cpython-18b250f844bf8b2d1a81c2d2dcc74e850364fe35.tar.bz2 |
bpo-29793: Convert some builtin types constructors to Argument Clinic. (#615)
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 33 |
1 files changed, 16 insertions, 17 deletions
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 @@ error: } 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 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 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 @@ static PyGetSetDef float_getset[] = { {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 @@ PyTypeObject PyFloat_Type = { 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 */ |