mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
bpo-29793: Convert some builtin types constructors to Argument Clinic. (#615)
This commit is contained in:
parent
0b5615926a
commit
18b250f844
14 changed files with 527 additions and 202 deletions
|
|
@ -1612,19 +1612,23 @@ float_as_integer_ratio_impl(PyObject *self)
|
|||
}
|
||||
|
||||
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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue