diff options
author | Batuhan Taskaya <batuhan@python.org> | 2021-07-16 15:43:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-16 15:43:02 (GMT) |
commit | 9af34c935185eca497617a216d141c72ffaeae9c (patch) | |
tree | 06c965d71e81caaec5193a5220709136b2f5e8d3 /Python/clinic | |
parent | 7915c96ffd7ddc5cb6d54015ee4c31255a416892 (diff) | |
download | cpython-9af34c935185eca497617a216d141c72ffaeae9c.zip cpython-9af34c935185eca497617a216d141c72ffaeae9c.tar.gz cpython-9af34c935185eca497617a216d141c72ffaeae9c.tar.bz2 |
bpo-20201: variadic arguments support for AC (GH-18609)
Implement support for `*args` in AC, and port `print()` to use it.
Diffstat (limited to 'Python/clinic')
-rw-r--r-- | Python/clinic/bltinmodule.c.h | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 4ea5876..1fade99 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -674,6 +674,80 @@ exit: return return_value; } +PyDoc_STRVAR(builtin_print__doc__, +"print($module, /, *args, sep=\' \', end=\'\\n\', file=None, flush=False)\n" +"--\n" +"\n" +"Prints the values to a stream, or to sys.stdout by default.\n" +"\n" +" sep\n" +" string inserted between values, default a space.\n" +" end\n" +" string appended after the last value, default a newline.\n" +" file\n" +" a file-like object (stream); defaults to the current sys.stdout.\n" +" flush\n" +" whether to forcibly flush the stream."); + +#define BUILTIN_PRINT_METHODDEF \ + {"print", (PyCFunction)(void(*)(void))builtin_print, METH_FASTCALL|METH_KEYWORDS, builtin_print__doc__}, + +static PyObject * +builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, + PyObject *end, PyObject *file, int flush); + +static PyObject * +builtin_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"sep", "end", "file", "flush", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "print", 0}; + PyObject *argsbuf[5]; + Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + PyObject *__clinic_args = NULL; + PyObject *sep = Py_None; + PyObject *end = Py_None; + PyObject *file = Py_None; + int flush = 0; + + args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf); + if (!args) { + goto exit; + } + __clinic_args = args[0]; + if (!noptargs) { + goto skip_optional_kwonly; + } + if (args[1]) { + sep = args[1]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[2]) { + end = args[2]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[3]) { + file = args[3]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + flush = PyObject_IsTrue(args[4]); + if (flush < 0) { + goto exit; + } +skip_optional_kwonly: + return_value = builtin_print_impl(module, __clinic_args, sep, end, file, flush); + +exit: + Py_XDECREF(__clinic_args); + return return_value; +} + PyDoc_STRVAR(builtin_input__doc__, "input($module, prompt=None, /)\n" "--\n" @@ -877,4 +951,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=e1d8057298b5de61 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=77ace832b3fb38e0 input=a9049054013a1b77]*/ |