diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-12-25 11:23:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-25 11:23:47 (GMT) |
commit | 32d96a2b5bc3136d45a66adbdb45fac351b520ce (patch) | |
tree | acf51c9945f764ab103597c9cba376f154aa600d /Objects/clinic/unicodeobject.c.h | |
parent | 65ce60aef150776f884715b4315a10a0d6ae769e (diff) | |
download | cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.zip cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.tar.gz cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.tar.bz2 |
bpo-23867: Argument Clinic: inline parsing code for a single positional parameter. (GH-9689)
Diffstat (limited to 'Objects/clinic/unicodeobject.c.h')
-rw-r--r-- | Objects/clinic/unicodeobject.c.h | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 273ae92..744a6eb 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -898,9 +898,23 @@ unicode_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 = unicode_zfill_impl(self, width); exit: @@ -925,9 +939,14 @@ unicode___format__(PyObject *self, PyObject *arg) PyObject *return_value = NULL; PyObject *format_spec; - if (!PyArg_Parse(arg, "U:__format__", &format_spec)) { + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("__format__", "str", arg); + goto exit; + } + if (PyUnicode_READY(arg) == -1) { goto exit; } + format_spec = arg; return_value = unicode___format___impl(self, format_spec); exit: @@ -951,4 +970,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=d323802b67bfc6d8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ff6acd5abd1998eb input=a9049054013a1b77]*/ |