summaryrefslogtreecommitdiff
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-15 17:51:14 +0200
committerGitHub <noreply@github.com>2017-11-15 17:51:14 +0200
commitaca7f574b06c72c85a5e3e4b16a8a5e384a7c4a8 (patch)
tree7a6c4059603b006765f7f857fcf2f9698d9b7bc2 /Python/bltinmodule.c
parent00987f6230fcdbecc8d9ab4b2b9fae8f99a1a4a9 (diff)
downloadcpython-git-aca7f574b06c72c85a5e3e4b16a8a5e384a7c4a8.tar.gz
bpo-30950: Convert round() to Argument Clinic. (#2740)
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 8eac0af352..81774dc5f8 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2079,19 +2079,23 @@ builtin_repr(PyObject *module, PyObject *obj)
}
-/* AC: cannot convert yet, as needs PEP 457 group support in inspect
- * or a semantic change to accept None for "ndigits"
- */
+/*[clinic input]
+round as builtin_round
+
+ number: object
+ ndigits: object = NULL
+
+Round a number to a given precision in decimal digits.
+
+The return value is an integer if ndigits is omitted or None. Otherwise
+the return value has the same type as the number. ndigits may be negative.
+[clinic start generated code]*/
+
static PyObject *
-builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
+builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits)
+/*[clinic end generated code: output=ff0d9dd176c02ede input=854bc3a217530c3d]*/
{
- PyObject *ndigits = NULL;
- static char *kwlist[] = {"number", "ndigits", 0};
- PyObject *number, *round, *result;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round",
- kwlist, &number, &ndigits))
- return NULL;
+ PyObject *round, *result;
if (Py_TYPE(number)->tp_dict == NULL) {
if (PyType_Ready(Py_TYPE(number)) < 0)
@@ -2115,13 +2119,6 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
return result;
}
-PyDoc_STRVAR(round_doc,
-"round(number[, ndigits]) -> number\n\
-\n\
-Round a number to a given precision in decimal digits (default 0 digits).\n\
-This returns an int when called with one argument, otherwise the\n\
-same type as the number. ndigits may be negative.");
-
/*AC: we need to keep the kwds dict intact to easily call into the
* list.sort method, which isn't currently supported in AC. So we just use
@@ -2679,7 +2676,7 @@ static PyMethodDef builtin_methods[] = {
BUILTIN_POW_METHODDEF
{"print", (PyCFunction)builtin_print, METH_FASTCALL | METH_KEYWORDS, print_doc},
BUILTIN_REPR_METHODDEF
- {"round", (PyCFunction)builtin_round, METH_VARARGS | METH_KEYWORDS, round_doc},
+ BUILTIN_ROUND_METHODDEF
BUILTIN_SETATTR_METHODDEF
BUILTIN_SORTED_METHODDEF
BUILTIN_SUM_METHODDEF