mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
bpo-23867: Argument Clinic: inline parsing code for a single positional parameter. (GH-9689)
This commit is contained in:
parent
65ce60aef1
commit
32d96a2b5b
49 changed files with 1677 additions and 275 deletions
13
Objects/clinic/bytearrayobject.c.h
generated
13
Objects/clinic/bytearrayobject.c.h
generated
|
@ -354,7 +354,7 @@ bytearray_append(PyByteArrayObject *self, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
int item;
|
||||
|
||||
if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) {
|
||||
if (!_getbytevalue(arg, &item)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_append_impl(self, item);
|
||||
|
@ -430,7 +430,7 @@ bytearray_remove(PyByteArrayObject *self, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
int value;
|
||||
|
||||
if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) {
|
||||
if (!_getbytevalue(arg, &value)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_remove_impl(self, value);
|
||||
|
@ -640,9 +640,14 @@ bytearray_fromhex(PyTypeObject *type, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *string;
|
||||
|
||||
if (!PyArg_Parse(arg, "U:fromhex", &string)) {
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("fromhex", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
string = arg;
|
||||
return_value = bytearray_fromhex_impl(type, string);
|
||||
|
||||
exit:
|
||||
|
@ -712,4 +717,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return bytearray_sizeof_impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=b88bb192dddca6e1 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=cd3e13a1905a473c input=a9049054013a1b77]*/
|
||||
|
|
21
Objects/clinic/bytesobject.c.h
generated
21
Objects/clinic/bytesobject.c.h
generated
|
@ -66,7 +66,11 @@ bytes_partition(PyBytesObject *self, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
Py_buffer sep = {NULL, NULL};
|
||||
|
||||
if (!PyArg_Parse(arg, "y*:partition", &sep)) {
|
||||
if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyBuffer_IsContiguous(&sep, 'C')) {
|
||||
_PyArg_BadArgument("partition", "contiguous buffer", arg);
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytes_partition_impl(self, &sep);
|
||||
|
@ -105,7 +109,11 @@ bytes_rpartition(PyBytesObject *self, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
Py_buffer sep = {NULL, NULL};
|
||||
|
||||
if (!PyArg_Parse(arg, "y*:rpartition", &sep)) {
|
||||
if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyBuffer_IsContiguous(&sep, 'C')) {
|
||||
_PyArg_BadArgument("rpartition", "contiguous buffer", arg);
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytes_rpartition_impl(self, &sep);
|
||||
|
@ -491,12 +499,17 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *string;
|
||||
|
||||
if (!PyArg_Parse(arg, "U:fromhex", &string)) {
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("fromhex", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
string = arg;
|
||||
return_value = bytes_fromhex_impl(type, string);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=07b33ac65362301b input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=dc9aa04f0007ab11 input=a9049054013a1b77]*/
|
||||
|
|
21
Objects/clinic/floatobject.c.h
generated
21
Objects/clinic/floatobject.c.h
generated
|
@ -228,7 +228,17 @@ float___getformat__(PyTypeObject *type, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
const char *typestr;
|
||||
|
||||
if (!PyArg_Parse(arg, "s:__getformat__", &typestr)) {
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("__getformat__", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
Py_ssize_t typestr_length;
|
||||
typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length);
|
||||
if (typestr == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
if (strlen(typestr) != (size_t)typestr_length) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
goto exit;
|
||||
}
|
||||
return_value = float___getformat___impl(type, typestr);
|
||||
|
@ -297,12 +307,17 @@ float___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 = float___format___impl(self, format_spec);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=091dd499f5386a6c input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=e8f8be828462d58b input=a9049054013a1b77]*/
|
||||
|
|
9
Objects/clinic/longobject.c.h
generated
9
Objects/clinic/longobject.c.h
generated
|
@ -58,9 +58,14 @@ int___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 = int___format___impl(self, format_spec);
|
||||
|
||||
exit:
|
||||
|
@ -239,4 +244,4 @@ int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyOb
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=403ccd096555fd1e input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=7436b5f4decdcf9d input=a9049054013a1b77]*/
|
||||
|
|
17
Objects/clinic/typeobject.c.h
generated
17
Objects/clinic/typeobject.c.h
generated
|
@ -166,7 +166,13 @@ object___reduce_ex__(PyObject *self, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
int protocol;
|
||||
|
||||
if (!PyArg_Parse(arg, "i:__reduce_ex__", &protocol)) {
|
||||
if (PyFloat_Check(arg)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"integer argument expected, got float" );
|
||||
goto exit;
|
||||
}
|
||||
protocol = _PyLong_AsInt(arg);
|
||||
if (protocol == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = object___reduce_ex___impl(self, protocol);
|
||||
|
@ -193,9 +199,14 @@ object___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 = object___format___impl(self, format_spec);
|
||||
|
||||
exit:
|
||||
|
@ -237,4 +248,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return object___dir___impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=8c4c856859564eaa input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=09f3453839e60136 input=a9049054013a1b77]*/
|
||||
|
|
25
Objects/clinic/unicodeobject.c.h
generated
25
Objects/clinic/unicodeobject.c.h
generated
|
@ -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]*/
|
||||
|
|
|
@ -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]*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue