From 32d96a2b5bc3136d45a66adbdb45fac351b520ce Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 25 Dec 2018 13:23:47 +0200 Subject: bpo-23867: Argument Clinic: inline parsing code for a single positional parameter. (GH-9689) --- Objects/stringlib/clinic/transmogrify.h.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Objects/stringlib') diff --git a/Objects/stringlib/clinic/transmogrify.h.h b/Objects/stringlib/clinic/transmogrify.h.h index fb63060d45..7b7fd58c7e 100644 --- a/Objects/stringlib/clinic/transmogrify.h.h +++ b/Objects/stringlib/clinic/transmogrify.h.h @@ -147,12 +147,26 @@ stringlib_zfill(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t width; - if (!PyArg_Parse(arg, "n:zfill", &width)) { + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(arg); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } return_value = stringlib_zfill_impl(self, width); exit: return return_value; } -/*[clinic end generated code: output=d09ba158d470566e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bf2ef501639e1190 input=a9049054013a1b77]*/ -- cgit v1.2.1