From e61cceeeacea42566240bc7635bc8cc2f4168cf1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Aug 2014 23:30:40 +0200 Subject: Issue #22156: Fix "comparison between signed and unsigned integers" compiler warnings in the Python/ subdirectory. --- Python/bltinmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index d905ba2d94..d2d1698139 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -581,7 +581,7 @@ source_as_string(PyObject *cmd, char *funcname, char *what, PyCompilerFlags *cf) return NULL; } - if (strlen(str) != size) { + if (strlen(str) != (size_t)size) { PyErr_SetString(PyExc_TypeError, "source code string cannot contain null bytes"); return NULL; -- cgit v1.2.1 From b2192492678248a0fd80d05ded9184d27ab0b395 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Sun, 17 Aug 2014 14:01:19 +1000 Subject: Issue #20184: Add signature introspection for 30 of the builtins Also adds a test to test_inspect to track progress on builtin introspection support, to ensure it doesn't regress in the future. --- Python/bltinmodule.c | 1561 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 1188 insertions(+), 373 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index d2d1698139..cbadc12218 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -46,6 +46,7 @@ _Py_IDENTIFIER(stdin); _Py_IDENTIFIER(stdout); _Py_IDENTIFIER(stderr); +/* AC: cannot convert yet, waiting for *args support */ static PyObject * builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) { @@ -229,25 +230,62 @@ absolute or relative imports. 0 is absolute while a positive number\n\ is the number of parent directories to search relative to the current module."); +/*[clinic input] +abs as builtin_abs + + x: 'O' + / + +Return the absolute value of the argument. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_abs__doc__, +"abs($module, x, /)\n" +"--\n" +"\n" +"Return the absolute value of the argument."); + +#define BUILTIN_ABS_METHODDEF \ + {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__}, + static PyObject * -builtin_abs(PyObject *self, PyObject *v) +builtin_abs(PyModuleDef *module, PyObject *x) +/*[clinic end generated code: output=f85095528ce7e2e5 input=aa29cc07869b4732]*/ { - return PyNumber_Absolute(v); + return PyNumber_Absolute(x); } -PyDoc_STRVAR(abs_doc, -"abs(number) -> number\n\ -\n\ -Return the absolute value of the argument."); +/*[clinic input] +all as builtin_all + + iterable: 'O' + / + +Return True if bool(x) is True for all values x in the iterable. + +If the iterable is empty, return True. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_all__doc__, +"all($module, iterable, /)\n" +"--\n" +"\n" +"Return True if bool(x) is True for all values x in the iterable.\n" +"\n" +"If the iterable is empty, return True."); + +#define BUILTIN_ALL_METHODDEF \ + {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__}, static PyObject * -builtin_all(PyObject *self, PyObject *v) +builtin_all(PyModuleDef *module, PyObject *iterable) +/*[clinic end generated code: output=d001db739ba83b46 input=dd506dc9998d42bd]*/ { PyObject *it, *item; PyObject *(*iternext)(PyObject *); int cmp; - it = PyObject_GetIter(v); + it = PyObject_GetIter(iterable); if (it == NULL) return NULL; iternext = *Py_TYPE(it)->tp_iternext; @@ -277,20 +315,37 @@ builtin_all(PyObject *self, PyObject *v) Py_RETURN_TRUE; } -PyDoc_STRVAR(all_doc, -"all(iterable) -> bool\n\ -\n\ -Return True if bool(x) is True for all values x in the iterable.\n\ -If the iterable is empty, return True."); +/*[clinic input] +any as builtin_any + + iterable: 'O' + / + +Return True if bool(x) is True for any x in the iterable. + +If the iterable is empty, return False. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_any__doc__, +"any($module, iterable, /)\n" +"--\n" +"\n" +"Return True if bool(x) is True for any x in the iterable.\n" +"\n" +"If the iterable is empty, return False."); + +#define BUILTIN_ANY_METHODDEF \ + {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__}, static PyObject * -builtin_any(PyObject *self, PyObject *v) +builtin_any(PyModuleDef *module, PyObject *iterable) +/*[clinic end generated code: output=3a4b6dbe6a0d6f61 input=8fe8460f3fbbced8]*/ { PyObject *it, *item; PyObject *(*iternext)(PyObject *); int cmp; - it = PyObject_GetIter(v); + it = PyObject_GetIter(iterable); if (it == NULL) return NULL; iternext = *Py_TYPE(it)->tp_iternext; @@ -320,56 +375,105 @@ builtin_any(PyObject *self, PyObject *v) Py_RETURN_FALSE; } -PyDoc_STRVAR(any_doc, -"any(iterable) -> bool\n\ -\n\ -Return True if bool(x) is True for any x in the iterable.\n\ -If the iterable is empty, return False."); +/*[clinic input] +ascii as builtin_ascii + + obj: 'O' + / + +Return an ASCII-only representation of an object. + +As repr(), return a string containing a printable representation of an +object, but escape the non-ASCII characters in the string returned by +repr() using \\x, \\u or \\U escapes. This generates a string similar +to that returned by repr() in Python 2. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_ascii__doc__, +"ascii($module, obj, /)\n" +"--\n" +"\n" +"Return an ASCII-only representation of an object.\n" +"\n" +"As repr(), return a string containing a printable representation of an\n" +"object, but escape the non-ASCII characters in the string returned by\n" +"repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n" +"to that returned by repr() in Python 2."); + +#define BUILTIN_ASCII_METHODDEF \ + {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__}, static PyObject * -builtin_ascii(PyObject *self, PyObject *v) +builtin_ascii(PyModuleDef *module, PyObject *obj) +/*[clinic end generated code: output=f0e6754154c2d30b input=0cbdc1420a306325]*/ { - return PyObject_ASCII(v); + return PyObject_ASCII(obj); } -PyDoc_STRVAR(ascii_doc, -"ascii(object) -> string\n\ -\n\ -As repr(), return a string containing a printable representation of an\n\ -object, but escape the non-ASCII characters in the string returned by\n\ -repr() using \\x, \\u or \\U escapes. This generates a string similar\n\ -to that returned by repr() in Python 2."); +/*[clinic input] +bin as builtin_bin + + number: 'O' + / + +Return the binary representation of an integer. + + >>> bin(2796202) + '0b1010101010101010101010' +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_bin__doc__, +"bin($module, number, /)\n" +"--\n" +"\n" +"Return the binary representation of an integer.\n" +"\n" +" >>> bin(2796202)\n" +" \'0b1010101010101010101010\'"); + +#define BUILTIN_BIN_METHODDEF \ + {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__}, static PyObject * -builtin_bin(PyObject *self, PyObject *v) +builtin_bin(PyModuleDef *module, PyObject *number) +/*[clinic end generated code: output=18fed0e943650da1 input=2a6362ae9a9c9203]*/ { - return PyNumber_ToBase(v, 2); + return PyNumber_ToBase(number, 2); } -PyDoc_STRVAR(bin_doc, -"bin(number) -> string\n\ -\n\ -Return the binary representation of an integer.\n\ -\n\ - >>> bin(2796202)\n\ - '0b1010101010101010101010'\n\ -"); +/*[clinic input] +callable as builtin_callable + + obj: 'O' + / + +Return whether the object is callable (i.e., some kind of function). + +Note that classes are callable, as are instances of classes with a +__call__() method. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_callable__doc__, +"callable($module, obj, /)\n" +"--\n" +"\n" +"Return whether the object is callable (i.e., some kind of function).\n" +"\n" +"Note that classes are callable, as are instances of classes with a\n" +"__call__() method."); + +#define BUILTIN_CALLABLE_METHODDEF \ + {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__}, static PyObject * -builtin_callable(PyObject *self, PyObject *v) +builtin_callable(PyModuleDef *module, PyObject *obj) +/*[clinic end generated code: output=b3a92cbe635f32af input=bb3bb528fffdade4]*/ { - return PyBool_FromLong((long)PyCallable_Check(v)); + return PyBool_FromLong((long)PyCallable_Check(obj)); } -PyDoc_STRVAR(callable_doc, -"callable(object) -> bool\n\ -\n\ -Return whether the object is callable (i.e., some kind of function).\n\ -Note that classes are callable, as are instances of classes with a\n\ -__call__() method."); - typedef struct { PyObject_HEAD @@ -524,39 +628,99 @@ PyTypeObject PyFilter_Type = { }; +/*[clinic input] +format as builtin_format + + value: 'O' + format_spec: unicode(c_default="NULL") = '' + / + +Return value.__format__(format_spec) + +format_spec defaults to the empty string +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_format__doc__, +"format($module, value, format_spec=\'\', /)\n" +"--\n" +"\n" +"Return value.__format__(format_spec)\n" +"\n" +"format_spec defaults to the empty string"); + +#define BUILTIN_FORMAT_METHODDEF \ + {"format", (PyCFunction)builtin_format, METH_VARARGS, builtin_format__doc__}, + +static PyObject * +builtin_format_impl(PyModuleDef *module, PyObject *value, PyObject *format_spec); + static PyObject * -builtin_format(PyObject *self, PyObject *args) +builtin_format(PyModuleDef *module, PyObject *args) { + PyObject *return_value = NULL; PyObject *value; PyObject *format_spec = NULL; - if (!PyArg_ParseTuple(args, "O|U:format", &value, &format_spec)) - return NULL; + if (!PyArg_ParseTuple(args, + "O|U:format", + &value, &format_spec)) + goto exit; + return_value = builtin_format_impl(module, value, format_spec); + +exit: + return return_value; +} +static PyObject * +builtin_format_impl(PyModuleDef *module, PyObject *value, PyObject *format_spec) +/*[clinic end generated code: output=39723a58c72e8871 input=e23f2f11e0098c64]*/ +{ return PyObject_Format(value, format_spec); } -PyDoc_STRVAR(format_doc, -"format(value[, format_spec]) -> string\n\ -\n\ -Returns value.__format__(format_spec)\n\ -format_spec defaults to \"\""); +/*[clinic input] +chr as builtin_chr + + i: 'i' + / + +Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_chr__doc__, +"chr($module, i, /)\n" +"--\n" +"\n" +"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); + +#define BUILTIN_CHR_METHODDEF \ + {"chr", (PyCFunction)builtin_chr, METH_VARARGS, builtin_chr__doc__}, static PyObject * -builtin_chr(PyObject *self, PyObject *args) +builtin_chr_impl(PyModuleDef *module, int i); + +static PyObject * +builtin_chr(PyModuleDef *module, PyObject *args) { - int x; + PyObject *return_value = NULL; + int i; - if (!PyArg_ParseTuple(args, "i:chr", &x)) - return NULL; + if (!PyArg_ParseTuple(args, + "i:chr", + &i)) + goto exit; + return_value = builtin_chr_impl(module, i); - return PyUnicode_FromOrdinal(x); +exit: + return return_value; } -PyDoc_STRVAR(chr_doc, -"chr(i) -> Unicode character\n\ -\n\ -Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); +static PyObject * +builtin_chr_impl(PyModuleDef *module, int i) +/*[clinic end generated code: output=4d6bbe948f56e2ae input=9b1ced29615adf66]*/ +{ + return PyUnicode_FromOrdinal(i); +} static char * @@ -589,34 +753,90 @@ source_as_string(PyObject *cmd, char *funcname, char *what, PyCompilerFlags *cf) return str; } +/*[clinic input] +compile as builtin_compile + + source: 'O' + filename: object(converter="PyUnicode_FSDecoder") + mode: 's' + flags: 'i' = 0 + dont_inherit: 'i' = 0 + optimize: 'i' = -1 + +Compile source into a code object that can be executed by exec() or eval(). + +The source code may represent a Python module, statement or expression. +The filename will be used for run-time error messages. +The mode must be 'exec' to compile a module, 'single' to compile a +single (interactive) statement, or 'eval' to compile an expression. +The flags argument, if present, controls which future statements influence +the compilation of the code. +The dont_inherit argument, if non-zero, stops the compilation inheriting +the effects of any future statements in effect in the code calling +compile; if absent or zero these statements do influence the compilation, +in addition to any features explicitly specified. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_compile__doc__, +"compile($module, /, source, filename, mode, flags=0, dont_inherit=0,\n" +" optimize=-1)\n" +"--\n" +"\n" +"Compile source into a code object that can be executed by exec() or eval().\n" +"\n" +"The source code may represent a Python module, statement or expression.\n" +"The filename will be used for run-time error messages.\n" +"The mode must be \'exec\' to compile a module, \'single\' to compile a\n" +"single (interactive) statement, or \'eval\' to compile an expression.\n" +"The flags argument, if present, controls which future statements influence\n" +"the compilation of the code.\n" +"The dont_inherit argument, if non-zero, stops the compilation inheriting\n" +"the effects of any future statements in effect in the code calling\n" +"compile; if absent or zero these statements do influence the compilation,\n" +"in addition to any features explicitly specified."); + +#define BUILTIN_COMPILE_METHODDEF \ + {"compile", (PyCFunction)builtin_compile, METH_VARARGS|METH_KEYWORDS, builtin_compile__doc__}, + +static PyObject * +builtin_compile_impl(PyModuleDef *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, int optimize); + static PyObject * -builtin_compile(PyObject *self, PyObject *args, PyObject *kwds) +builtin_compile(PyModuleDef *module, PyObject *args, PyObject *kwargs) { - char *str; + PyObject *return_value = NULL; + static char *_keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL}; + PyObject *source; PyObject *filename; - char *startstr; - int mode = -1; + const char *mode; + int flags = 0; int dont_inherit = 0; - int supplied_flags = 0; int optimize = -1; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "OO&s|iii:compile", _keywords, + &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) + goto exit; + return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize); + +exit: + return return_value; +} + +static PyObject * +builtin_compile_impl(PyModuleDef *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, int optimize) +/*[clinic end generated code: output=c72d197809d178fc input=c6212a9d21472f7e]*/ +{ + char *str; + int compile_mode = -1; int is_ast; PyCompilerFlags cf; - PyObject *cmd; - static char *kwlist[] = {"source", "filename", "mode", "flags", - "dont_inherit", "optimize", NULL}; int start[] = {Py_file_input, Py_eval_input, Py_single_input}; PyObject *result; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&s|iii:compile", kwlist, - &cmd, - PyUnicode_FSDecoder, &filename, - &startstr, &supplied_flags, - &dont_inherit, &optimize)) - return NULL; - - cf.cf_flags = supplied_flags | PyCF_SOURCE_IS_UTF8; + cf.cf_flags = flags | PyCF_SOURCE_IS_UTF8; - if (supplied_flags & + if (flags & ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | PyCF_ONLY_AST)) { PyErr_SetString(PyExc_ValueError, @@ -635,25 +855,25 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds) PyEval_MergeCompilerFlags(&cf); } - if (strcmp(startstr, "exec") == 0) - mode = 0; - else if (strcmp(startstr, "eval") == 0) - mode = 1; - else if (strcmp(startstr, "single") == 0) - mode = 2; + if (strcmp(mode, "exec") == 0) + compile_mode = 0; + else if (strcmp(mode, "eval") == 0) + compile_mode = 1; + else if (strcmp(mode, "single") == 0) + compile_mode = 2; else { PyErr_SetString(PyExc_ValueError, - "compile() arg 3 must be 'exec', 'eval' or 'single'"); + "compile() mode must be 'exec', 'eval' or 'single'"); goto error; } - is_ast = PyAST_Check(cmd); + is_ast = PyAST_Check(source); if (is_ast == -1) goto error; if (is_ast) { - if (supplied_flags & PyCF_ONLY_AST) { - Py_INCREF(cmd); - result = cmd; + if (flags & PyCF_ONLY_AST) { + Py_INCREF(source); + result = source; } else { PyArena *arena; @@ -662,7 +882,7 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds) arena = PyArena_New(); if (arena == NULL) goto error; - mod = PyAST_obj2mod(cmd, arena, mode); + mod = PyAST_obj2mod(source, arena, compile_mode); if (mod == NULL) { PyArena_Free(arena); goto error; @@ -678,11 +898,11 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds) goto finally; } - str = source_as_string(cmd, "compile", "string, bytes or AST", &cf); + str = source_as_string(source, "compile", "string, bytes or AST", &cf); if (str == NULL) goto error; - result = Py_CompileStringObject(str, filename, start[mode], &cf, optimize); + result = Py_CompileStringObject(str, filename, start[compile_mode], &cf, optimize); goto finally; error: @@ -692,21 +912,7 @@ finally: return result; } -PyDoc_STRVAR(compile_doc, -"compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\ -\n\ -Compile the source (a Python module, statement or expression)\n\ -into a code object that can be executed by exec() or eval().\n\ -The filename will be used for run-time error messages.\n\ -The mode must be 'exec' to compile a module, 'single' to compile a\n\ -single (interactive) statement, or 'eval' to compile an expression.\n\ -The flags argument, if present, controls which future statements influence\n\ -the compilation of the code.\n\ -The dont_inherit argument, if non-zero, stops the compilation inheriting\n\ -the effects of any future statements in effect in the code calling\n\ -compile; if absent or zero these statements do influence the compilation,\n\ -in addition to any features explicitly specified."); - +/* AC: cannot convert yet, as needs PEP 457 group support in inspect */ static PyObject * builtin_dir(PyObject *self, PyObject *args) { @@ -731,32 +937,114 @@ PyDoc_STRVAR(dir_doc, " for any other object: its attributes, its class's attributes, and\n" " recursively the attributes of its class's base classes."); +/*[clinic input] +divmod as builtin_divmod + + x: 'O' + y: 'O' + / + +Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_divmod__doc__, +"divmod($module, x, y, /)\n" +"--\n" +"\n" +"Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."); + +#define BUILTIN_DIVMOD_METHODDEF \ + {"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__}, + static PyObject * -builtin_divmod(PyObject *self, PyObject *args) +builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y); + +static PyObject * +builtin_divmod(PyModuleDef *module, PyObject *args) { - PyObject *v, *w; + PyObject *return_value = NULL; + PyObject *x; + PyObject *y; + + if (!PyArg_UnpackTuple(args, "divmod", + 2, 2, + &x, &y)) + goto exit; + return_value = builtin_divmod_impl(module, x, y); + +exit: + return return_value; +} - if (!PyArg_UnpackTuple(args, "divmod", 2, 2, &v, &w)) - return NULL; - return PyNumber_Divmod(v, w); +static PyObject * +builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y) +/*[clinic end generated code: output=77e8d408b1338886 input=c9c617b7bb74c615]*/ +{ + return PyNumber_Divmod(x, y); } -PyDoc_STRVAR(divmod_doc, -"divmod(x, y) -> (div, mod)\n\ -\n\ -Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."); +/*[clinic input] +eval as builtin_eval + + source: 'O' + globals: 'O' = None + locals: 'O' = None + / + +Evaluate the given source in the context of globals and locals. + +The source may be a string representing a Python expression +or a code object as returned by compile(). +The globals must be a dictionary and locals can be any mapping, +defaulting to the current globals and locals. +If only globals is given, locals defaults to it. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_eval__doc__, +"eval($module, source, globals=None, locals=None, /)\n" +"--\n" +"\n" +"Evaluate the given source in the context of globals and locals.\n" +"\n" +"The source may be a string representing a Python expression\n" +"or a code object as returned by compile().\n" +"The globals must be a dictionary and locals can be any mapping,\n" +"defaulting to the current globals and locals.\n" +"If only globals is given, locals defaults to it."); + +#define BUILTIN_EVAL_METHODDEF \ + {"eval", (PyCFunction)builtin_eval, METH_VARARGS, builtin_eval__doc__}, + +static PyObject * +builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals); + +static PyObject * +builtin_eval(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *source; + PyObject *globals = Py_None; + PyObject *locals = Py_None; + + if (!PyArg_UnpackTuple(args, "eval", + 1, 3, + &source, &globals, &locals)) + goto exit; + return_value = builtin_eval_impl(module, source, globals, locals); + +exit: + return return_value; +} static PyObject * -builtin_eval(PyObject *self, PyObject *args) +builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals) +/*[clinic end generated code: output=644fd59012538ce6 input=31e42c1d2125b50b]*/ { - PyObject *cmd, *result, *tmp = NULL; - PyObject *globals = Py_None, *locals = Py_None; + PyObject *result, *tmp = NULL; char *str; PyCompilerFlags cf; - if (!PyArg_UnpackTuple(args, "eval", 1, 3, &cmd, &globals, &locals)) - return NULL; if (locals != Py_None && !PyMapping_Check(locals)) { PyErr_SetString(PyExc_TypeError, "locals must be a mapping"); return NULL; @@ -791,17 +1079,17 @@ builtin_eval(PyObject *self, PyObject *args) return NULL; } - if (PyCode_Check(cmd)) { - if (PyCode_GetNumFree((PyCodeObject *)cmd) > 0) { + if (PyCode_Check(source)) { + if (PyCode_GetNumFree((PyCodeObject *)source) > 0) { PyErr_SetString(PyExc_TypeError, "code object passed to eval() may not contain free variables"); return NULL; } - return PyEval_EvalCode(cmd, globals, locals); + return PyEval_EvalCode(source, globals, locals); } cf.cf_flags = PyCF_SOURCE_IS_UTF8; - str = source_as_string(cmd, "eval", "string, bytes or code", &cf); + str = source_as_string(source, "eval", "string, bytes or code", &cf); if (str == NULL) return NULL; @@ -814,24 +1102,64 @@ builtin_eval(PyObject *self, PyObject *args) return result; } -PyDoc_STRVAR(eval_doc, -"eval(source[, globals[, locals]]) -> value\n\ -\n\ -Evaluate the source in the context of globals and locals.\n\ -The source may be a string representing a Python expression\n\ -or a code object as returned by compile().\n\ -The globals must be a dictionary and locals can be any mapping,\n\ -defaulting to the current globals and locals.\n\ -If only globals is given, locals defaults to it.\n"); +/*[clinic input] +exec as builtin_exec + + source: 'O' + globals: 'O' = None + locals: 'O' = None + / + +Execute the given source in the context of globals and locals. + +The source may be a string representing one or more Python statements +or a code object as returned by compile(). +The globals must be a dictionary and locals can be any mapping, +defaulting to the current globals and locals. +If only globals is given, locals defaults to it. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_exec__doc__, +"exec($module, source, globals=None, locals=None, /)\n" +"--\n" +"\n" +"Execute the given source in the context of globals and locals.\n" +"\n" +"The source may be a string representing one or more Python statements\n" +"or a code object as returned by compile().\n" +"The globals must be a dictionary and locals can be any mapping,\n" +"defaulting to the current globals and locals.\n" +"If only globals is given, locals defaults to it."); + +#define BUILTIN_EXEC_METHODDEF \ + {"exec", (PyCFunction)builtin_exec, METH_VARARGS, builtin_exec__doc__}, + +static PyObject * +builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals); static PyObject * -builtin_exec(PyObject *self, PyObject *args) +builtin_exec(PyModuleDef *module, PyObject *args) { - PyObject *v; - PyObject *prog, *globals = Py_None, *locals = Py_None; + PyObject *return_value = NULL; + PyObject *source; + PyObject *globals = Py_None; + PyObject *locals = Py_None; + + if (!PyArg_UnpackTuple(args, "exec", + 1, 3, + &source, &globals, &locals)) + goto exit; + return_value = builtin_exec_impl(module, source, globals, locals); + +exit: + return return_value; +} - if (!PyArg_UnpackTuple(args, "exec", 1, 3, &prog, &globals, &locals)) - return NULL; +static PyObject * +builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals) +/*[clinic end generated code: output=0281b48bfa8e3c87 input=536e057b5e00d89e]*/ +{ + PyObject *v; if (globals == Py_None) { globals = PyEval_GetGlobals(); @@ -850,13 +1178,13 @@ builtin_exec(PyObject *self, PyObject *args) locals = globals; if (!PyDict_Check(globals)) { - PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.100s", + PyErr_Format(PyExc_TypeError, "exec() globals must be a dict, not %.100s", globals->ob_type->tp_name); return NULL; } if (!PyMapping_Check(locals)) { PyErr_Format(PyExc_TypeError, - "arg 3 must be a mapping or None, not %.100s", + "locals must be a mapping or None, not %.100s", locals->ob_type->tp_name); return NULL; } @@ -866,21 +1194,21 @@ builtin_exec(PyObject *self, PyObject *args) return NULL; } - if (PyCode_Check(prog)) { - if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) { + if (PyCode_Check(source)) { + if (PyCode_GetNumFree((PyCodeObject *)source) > 0) { PyErr_SetString(PyExc_TypeError, "code object passed to exec() may not " "contain free variables"); return NULL; } - v = PyEval_EvalCode(prog, globals, locals); + v = PyEval_EvalCode(source, globals, locals); } else { char *str; PyCompilerFlags cf; cf.cf_flags = PyCF_SOURCE_IS_UTF8; - str = source_as_string(prog, "exec", - "string, bytes or code", &cf); + str = source_as_string(source, "exec", + "string, bytes or code", &cf); if (str == NULL) return NULL; if (PyEval_MergeCompilerFlags(&cf)) @@ -895,15 +1223,8 @@ builtin_exec(PyObject *self, PyObject *args) Py_RETURN_NONE; } -PyDoc_STRVAR(exec_doc, -"exec(object[, globals[, locals]])\n\ -\n\ -Read and execute code from an object, which can be a string or a code\n\ -object.\n\ -The globals and locals are dictionaries, defaulting to the current\n\ -globals and locals. If only globals is given, locals defaults to it."); - +/* AC: cannot convert yet, as needs PEP 457 group support in inspect */ static PyObject * builtin_getattr(PyObject *self, PyObject *args) { @@ -937,8 +1258,39 @@ When a default argument is given, it is returned when the attribute doesn't\n\ exist; without it, an exception is raised in that case."); +/*[clinic input] +globals as builtin_globals + +Return the dictionary containing the current scope's global variables. + +NOTE: Updates to this dictionary *will* affect name lookups in the current +global scope and vice-versa. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_globals__doc__, +"globals($module, /)\n" +"--\n" +"\n" +"Return the dictionary containing the current scope\'s global variables.\n" +"\n" +"NOTE: Updates to this dictionary *will* affect name lookups in the current\n" +"global scope and vice-versa."); + +#define BUILTIN_GLOBALS_METHODDEF \ + {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__}, + +static PyObject * +builtin_globals_impl(PyModuleDef *module); + static PyObject * -builtin_globals(PyObject *self) +builtin_globals(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return builtin_globals_impl(module); +} + +static PyObject * +builtin_globals_impl(PyModuleDef *module) +/*[clinic end generated code: output=048640f58b1f20ad input=9327576f92bb48ba]*/ { PyObject *d; @@ -947,26 +1299,62 @@ builtin_globals(PyObject *self) return d; } -PyDoc_STRVAR(globals_doc, -"globals() -> dictionary\n\ -\n\ -Return the dictionary containing the current scope's global variables."); +/*[clinic input] +hasattr as builtin_hasattr + + obj: 'O' + name: 'O' + / + +Return whether the object has an attribute with the given name. + +This is done by calling getattr(obj, name) and catching AttributeError. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_hasattr__doc__, +"hasattr($module, obj, name, /)\n" +"--\n" +"\n" +"Return whether the object has an attribute with the given name.\n" +"\n" +"This is done by calling getattr(obj, name) and catching AttributeError."); + +#define BUILTIN_HASATTR_METHODDEF \ + {"hasattr", (PyCFunction)builtin_hasattr, METH_VARARGS, builtin_hasattr__doc__}, static PyObject * -builtin_hasattr(PyObject *self, PyObject *args) +builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name); + +static PyObject * +builtin_hasattr(PyModuleDef *module, PyObject *args) { - PyObject *v; + PyObject *return_value = NULL; + PyObject *obj; PyObject *name; - if (!PyArg_UnpackTuple(args, "hasattr", 2, 2, &v, &name)) - return NULL; + if (!PyArg_UnpackTuple(args, "hasattr", + 2, 2, + &obj, &name)) + goto exit; + return_value = builtin_hasattr_impl(module, obj, name); + +exit: + return return_value; +} + +static PyObject * +builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) +/*[clinic end generated code: output=e0bd996ef73d1217 input=b50bad5f739ea10d]*/ +{ + PyObject *v; + if (!PyUnicode_Check(name)) { PyErr_SetString(PyExc_TypeError, "hasattr(): attribute name must be string"); return NULL; } - v = PyObject_GetAttr(v, name); + v = PyObject_GetAttr(obj, name); if (v == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); @@ -978,25 +1366,43 @@ builtin_hasattr(PyObject *self, PyObject *args) Py_RETURN_TRUE; } -PyDoc_STRVAR(hasattr_doc, -"hasattr(object, name) -> bool\n\ -\n\ -Return whether the object has an attribute with the given name.\n\ -(This is done by calling getattr(object, name) and catching AttributeError.)"); +/* AC: gdb's integration with CPython relies on builtin_id having + * the *exact* parameter names of "self" and "v", so we ensure we + * preserve those name rather than using the AC defaults. + */ +/*[clinic input] +id as builtin_id + + self: self(type="PyModuleDef *") + obj as v: 'O' + / + +Return the identity of an object. + +This is guaranteed to be unique among simultaneously existing objects. +(CPython uses the object's memory address.) +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_id__doc__, +"id($module, obj, /)\n" +"--\n" +"\n" +"Return the identity of an object.\n" +"\n" +"This is guaranteed to be unique among simultaneously existing objects.\n" +"(CPython uses the object\'s memory address.)"); + +#define BUILTIN_ID_METHODDEF \ + {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__}, static PyObject * -builtin_id(PyObject *self, PyObject *v) +builtin_id(PyModuleDef *self, PyObject *v) +/*[clinic end generated code: output=f54da09c91992e63 input=a1f988d98357341d]*/ { return PyLong_FromVoidPtr(v); } -PyDoc_STRVAR(id_doc, -"id(object) -> integer\n\ -\n\ -Return the identity of an object. This is guaranteed to be unique among\n\ -simultaneously existing objects. (Hint: it's the object's memory address.)"); - /* map object ************************************************************/ @@ -1169,6 +1575,8 @@ PyTypeObject PyMap_Type = { PyObject_GC_Del, /* tp_free */ }; + +/* AC: cannot convert yet, as needs PEP 457 group support in inspect */ static PyObject * builtin_next(PyObject *self, PyObject *args) { @@ -1210,83 +1618,186 @@ Return the next item from the iterator. If default is given and the iterator\n\ is exhausted, it is returned instead of raising StopIteration."); +/*[clinic input] +setattr as builtin_setattr + + obj: 'O' + name: 'O' + value: 'O' + / + +Sets the named attribute on the given object to the specified value. + +setattr(x, 'y', v) is equivalent to ``x.y = v'' +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_setattr__doc__, +"setattr($module, obj, name, value, /)\n" +"--\n" +"\n" +"Sets the named attribute on the given object to the specified value.\n" +"\n" +"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'"); + +#define BUILTIN_SETATTR_METHODDEF \ + {"setattr", (PyCFunction)builtin_setattr, METH_VARARGS, builtin_setattr__doc__}, + static PyObject * -builtin_setattr(PyObject *self, PyObject *args) +builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, PyObject *value); + +static PyObject * +builtin_setattr(PyModuleDef *module, PyObject *args) { - PyObject *v; + PyObject *return_value = NULL; + PyObject *obj; PyObject *name; PyObject *value; - if (!PyArg_UnpackTuple(args, "setattr", 3, 3, &v, &name, &value)) - return NULL; - if (PyObject_SetAttr(v, name, value) != 0) + if (!PyArg_UnpackTuple(args, "setattr", + 3, 3, + &obj, &name, &value)) + goto exit; + return_value = builtin_setattr_impl(module, obj, name, value); + +exit: + return return_value; +} + +static PyObject * +builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, PyObject *value) +/*[clinic end generated code: output=4336dcbbf7691d2d input=fbe7e53403116b93]*/ +{ + if (PyObject_SetAttr(obj, name, value) != 0) return NULL; Py_INCREF(Py_None); return Py_None; } -PyDoc_STRVAR(setattr_doc, -"setattr(object, name, value)\n\ -\n\ -Set a named attribute on an object; setattr(x, 'y', v) is equivalent to\n\ -``x.y = v''."); +/*[clinic input] +delattr as builtin_delattr + + obj: 'O' + name: 'O' + / + +Deletes the named attribute from the given object. + +delattr(x, 'y') is equivalent to ``del x.y'' +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_delattr__doc__, +"delattr($module, obj, name, /)\n" +"--\n" +"\n" +"Deletes the named attribute from the given object.\n" +"\n" +"delattr(x, \'y\') is equivalent to ``del x.y\'\'"); + +#define BUILTIN_DELATTR_METHODDEF \ + {"delattr", (PyCFunction)builtin_delattr, METH_VARARGS, builtin_delattr__doc__}, + +static PyObject * +builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name); static PyObject * -builtin_delattr(PyObject *self, PyObject *args) +builtin_delattr(PyModuleDef *module, PyObject *args) { - PyObject *v; + PyObject *return_value = NULL; + PyObject *obj; PyObject *name; - if (!PyArg_UnpackTuple(args, "delattr", 2, 2, &v, &name)) - return NULL; - if (PyObject_SetAttr(v, name, (PyObject *)NULL) != 0) + if (!PyArg_UnpackTuple(args, "delattr", + 2, 2, + &obj, &name)) + goto exit; + return_value = builtin_delattr_impl(module, obj, name); + +exit: + return return_value; +} + +static PyObject * +builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) +/*[clinic end generated code: output=319c2d884aa769cf input=647af2ce9183a823]*/ +{ + if (PyObject_SetAttr(obj, name, (PyObject *)NULL) != 0) return NULL; Py_INCREF(Py_None); return Py_None; } -PyDoc_STRVAR(delattr_doc, -"delattr(object, name)\n\ -\n\ -Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\ -``del x.y''."); +/*[clinic input] +hash as builtin_hash + + obj: 'O' + / + +Return the hash value for the given object. + +Two objects that compare equal must also have the same hash value, but the +reverse is not necessarily true. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_hash__doc__, +"hash($module, obj, /)\n" +"--\n" +"\n" +"Return the hash value for the given object.\n" +"\n" +"Two objects that compare equal must also have the same hash value, but the\n" +"reverse is not necessarily true."); + +#define BUILTIN_HASH_METHODDEF \ + {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__}, static PyObject * -builtin_hash(PyObject *self, PyObject *v) +builtin_hash(PyModuleDef *module, PyObject *obj) +/*[clinic end generated code: output=1ec467611c13468b input=ccc4d2b9a351df4e]*/ { Py_hash_t x; - x = PyObject_Hash(v); + x = PyObject_Hash(obj); if (x == -1) return NULL; return PyLong_FromSsize_t(x); } -PyDoc_STRVAR(hash_doc, -"hash(object) -> integer\n\ -\n\ -Return a hash value for the object. Two objects with the same value have\n\ -the same hash value. The reverse is not necessarily true, but likely."); +/*[clinic input] +hex as builtin_hex + + number: 'O' + / + +Return the hexadecimal representation of an integer. + + >>> hex(12648430) + '0xc0ffee' +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_hex__doc__, +"hex($module, number, /)\n" +"--\n" +"\n" +"Return the hexadecimal representation of an integer.\n" +"\n" +" >>> hex(12648430)\n" +" \'0xc0ffee\'"); + +#define BUILTIN_HEX_METHODDEF \ + {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__}, static PyObject * -builtin_hex(PyObject *self, PyObject *v) +builtin_hex(PyModuleDef *module, PyObject *number) +/*[clinic end generated code: output=f18e9439aeaa2c6c input=e816200b0a728ebe]*/ { - return PyNumber_ToBase(v, 16); + return PyNumber_ToBase(number, 16); } -PyDoc_STRVAR(hex_doc, -"hex(number) -> string\n\ -\n\ -Return the hexadecimal representation of an integer.\n\ -\n\ - >>> hex(3735928559)\n\ - '0xdeadbeef'\n\ -"); - +/* AC: cannot convert yet, as needs PEP 457 group support in inspect */ static PyObject * builtin_iter(PyObject *self, PyObject *args) { @@ -1313,25 +1824,72 @@ supply its own iterator, or be a sequence.\n\ In the second form, the callable is called until it returns the sentinel."); +/*[clinic input] +len as builtin_len + + obj: 'O' + / + +Return the number of items in a container. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_len__doc__, +"len($module, obj, /)\n" +"--\n" +"\n" +"Return the number of items in a container."); + +#define BUILTIN_LEN_METHODDEF \ + {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__}, + static PyObject * -builtin_len(PyObject *self, PyObject *v) +builtin_len(PyModuleDef *module, PyObject *obj) +/*[clinic end generated code: output=5a38b0db40761705 input=2e5ff15db9a2de22]*/ { Py_ssize_t res; - res = PyObject_Size(v); + res = PyObject_Size(obj); if (res < 0 && PyErr_Occurred()) return NULL; return PyLong_FromSsize_t(res); } -PyDoc_STRVAR(len_doc, -"len(object)\n\ -\n\ -Return the number of items of a sequence or collection."); +/*[clinic input] +locals as builtin_locals + +Return a dictionary containing the current scope's local variables. + +NOTE: Whether or not updates to this dictionary will affect name lookups in +the local scope and vice-versa is *implementation dependent* and not +covered by any backwards compatibility guarantees. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_locals__doc__, +"locals($module, /)\n" +"--\n" +"\n" +"Return a dictionary containing the current scope\'s local variables.\n" +"\n" +"NOTE: Whether or not updates to this dictionary will affect name lookups in\n" +"the local scope and vice-versa is *implementation dependent* and not\n" +"covered by any backwards compatibility guarantees."); + +#define BUILTIN_LOCALS_METHODDEF \ + {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__}, + +static PyObject * +builtin_locals_impl(PyModuleDef *module); + +static PyObject * +builtin_locals(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return builtin_locals_impl(module); +} static PyObject * -builtin_locals(PyObject *self) +builtin_locals_impl(PyModuleDef *module) +/*[clinic end generated code: output=8ac52522924346e2 input=7874018d478d5c4b]*/ { PyObject *d; @@ -1340,11 +1898,6 @@ builtin_locals(PyObject *self) return d; } -PyDoc_STRVAR(locals_doc, -"locals() -> dictionary\n\ -\n\ -Update and return a dictionary containing the current scope's local variables."); - static PyObject * min_max(PyObject *args, PyObject *kwds, int op) @@ -1447,6 +2000,7 @@ Fail_it: return NULL; } +/* AC: cannot convert yet, waiting for *args support */ static PyObject * builtin_min(PyObject *self, PyObject *args, PyObject *kwds) { @@ -1463,6 +2017,7 @@ the provided iterable is empty.\n\ With two or more arguments, return the smallest argument."); +/* AC: cannot convert yet, waiting for *args support */ static PyObject * builtin_max(PyObject *self, PyObject *args, PyObject *kwds) { @@ -1479,56 +2034,91 @@ the provided iterable is empty.\n\ With two or more arguments, return the largest argument."); +/*[clinic input] +oct as builtin_oct + + number: 'O' + / + +Return the octal representation of an integer. + + >>> oct(342391) + '0o1234567' +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_oct__doc__, +"oct($module, number, /)\n" +"--\n" +"\n" +"Return the octal representation of an integer.\n" +"\n" +" >>> oct(342391)\n" +" \'0o1234567\'"); + +#define BUILTIN_OCT_METHODDEF \ + {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__}, + static PyObject * -builtin_oct(PyObject *self, PyObject *v) +builtin_oct(PyModuleDef *module, PyObject *number) +/*[clinic end generated code: output=b99234d1d70a6673 input=a3a372b521b3dd13]*/ { - return PyNumber_ToBase(v, 8); + return PyNumber_ToBase(number, 8); } -PyDoc_STRVAR(oct_doc, -"oct(number) -> string\n\ -\n\ -Return the octal representation of an integer.\n\ -\n\ - >>> oct(342391)\n\ - '0o1234567'\n\ -"); +/*[clinic input] +ord as builtin_ord + + c: 'O' + / + +Return the Unicode code point for a one-character string. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_ord__doc__, +"ord($module, c, /)\n" +"--\n" +"\n" +"Return the Unicode code point for a one-character string."); + +#define BUILTIN_ORD_METHODDEF \ + {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__}, static PyObject * -builtin_ord(PyObject *self, PyObject* obj) +builtin_ord(PyModuleDef *module, PyObject *c) +/*[clinic end generated code: output=a8466d23bd76db3f input=762355f87451efa3]*/ { long ord; Py_ssize_t size; - if (PyBytes_Check(obj)) { - size = PyBytes_GET_SIZE(obj); + if (PyBytes_Check(c)) { + size = PyBytes_GET_SIZE(c); if (size == 1) { - ord = (long)((unsigned char)*PyBytes_AS_STRING(obj)); + ord = (long)((unsigned char)*PyBytes_AS_STRING(c)); return PyLong_FromLong(ord); } } - else if (PyUnicode_Check(obj)) { - if (PyUnicode_READY(obj) == -1) + else if (PyUnicode_Check(c)) { + if (PyUnicode_READY(c) == -1) return NULL; - size = PyUnicode_GET_LENGTH(obj); + size = PyUnicode_GET_LENGTH(c); if (size == 1) { - ord = (long)PyUnicode_READ_CHAR(obj, 0); + ord = (long)PyUnicode_READ_CHAR(c, 0); return PyLong_FromLong(ord); } } - else if (PyByteArray_Check(obj)) { + else if (PyByteArray_Check(c)) { /* XXX Hopefully this is temporary */ - size = PyByteArray_GET_SIZE(obj); + size = PyByteArray_GET_SIZE(c); if (size == 1) { - ord = (long)((unsigned char)*PyByteArray_AS_STRING(obj)); + ord = (long)((unsigned char)*PyByteArray_AS_STRING(c)); return PyLong_FromLong(ord); } } else { PyErr_Format(PyExc_TypeError, "ord() expected string of length 1, but " \ - "%.200s found", obj->ob_type->tp_name); + "%.200s found", c->ob_type->tp_name); return NULL; } @@ -1539,31 +2129,63 @@ builtin_ord(PyObject *self, PyObject* obj) return NULL; } -PyDoc_VAR(ord_doc) = PyDoc_STR( -"ord(c) -> integer\n\ -\n\ -Return the integer ordinal of a one-character string." -); +/*[clinic input] +pow as builtin_pow + + x: 'O' + y: 'O' + z: 'O' = None + / + +Equivalent to x**y (with two arguments) or x**y % z (with three arguments) + +Some types, such as ints, are able to use a more efficient algorithm when +invoked using the three argument form. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_pow__doc__, +"pow($module, x, y, z=None, /)\n" +"--\n" +"\n" +"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n" +"\n" +"Some types, such as ints, are able to use a more efficient algorithm when\n" +"invoked using the three argument form."); + +#define BUILTIN_POW_METHODDEF \ + {"pow", (PyCFunction)builtin_pow, METH_VARARGS, builtin_pow__doc__}, static PyObject * -builtin_pow(PyObject *self, PyObject *args) -{ - PyObject *v, *w, *z = Py_None; +builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z); - if (!PyArg_UnpackTuple(args, "pow", 2, 3, &v, &w, &z)) - return NULL; - return PyNumber_Power(v, w, z); +static PyObject * +builtin_pow(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *x; + PyObject *y; + PyObject *z = Py_None; + + if (!PyArg_UnpackTuple(args, "pow", + 2, 3, + &x, &y, &z)) + goto exit; + return_value = builtin_pow_impl(module, x, y, z); + +exit: + return return_value; } -PyDoc_STRVAR(pow_doc, -"pow(x, y[, z]) -> number\n\ -\n\ -With two arguments, equivalent to x**y. With three arguments,\n\ -equivalent to (x**y) % z, but may be more efficient (e.g. for ints)."); - +static PyObject * +builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z) +/*[clinic end generated code: output=d0cdf314311dedba input=561a942d5f5c1899]*/ +{ + return PyNumber_Power(x, y, z); +} +/* AC: cannot convert yet, waiting for *args support */ static PyObject * builtin_print(PyObject *self, PyObject *args, PyObject *kwds) { @@ -1659,10 +2281,59 @@ end: string appended after the last value, default a newline.\n\ flush: whether to forcibly flush the stream."); +/*[clinic input] +input as builtin_input + + prompt: object(c_default="NULL") = None + / + +Read a string from standard input. The trailing newline is stripped. + +The prompt string, if given, is printed to standard output without a +trailing newline before reading input. + +If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. +On *nix systems, readline is used if available. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_input__doc__, +"input($module, prompt=None, /)\n" +"--\n" +"\n" +"Read a string from standard input. The trailing newline is stripped.\n" +"\n" +"The prompt string, if given, is printed to standard output without a\n" +"trailing newline before reading input.\n" +"\n" +"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n" +"On *nix systems, readline is used if available."); + +#define BUILTIN_INPUT_METHODDEF \ + {"input", (PyCFunction)builtin_input, METH_VARARGS, builtin_input__doc__}, + static PyObject * -builtin_input(PyObject *self, PyObject *args) +builtin_input_impl(PyModuleDef *module, PyObject *prompt); + +static PyObject * +builtin_input(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *prompt = NULL; + + if (!PyArg_UnpackTuple(args, "input", + 0, 1, + &prompt)) + goto exit; + return_value = builtin_input_impl(module, prompt); + +exit: + return return_value; +} + +static PyObject * +builtin_input_impl(PyModuleDef *module, PyObject *prompt) +/*[clinic end generated code: output=69323bf5695f7c9c input=5e8bb70c2908fe3c]*/ { - PyObject *promptarg = NULL; PyObject *fin = _PySys_GetObjectId(&PyId_stdin); PyObject *fout = _PySys_GetObjectId(&PyId_stdout); PyObject *ferr = _PySys_GetObjectId(&PyId_stderr); @@ -1670,10 +2341,6 @@ builtin_input(PyObject *self, PyObject *args) long fd; int tty; - /* Parse arguments */ - if (!PyArg_UnpackTuple(args, "input", 0, 1, &promptarg)) - return NULL; - /* Check that stdin/out/err are intact */ if (fin == NULL || fin == Py_None) { PyErr_SetString(PyExc_RuntimeError, @@ -1729,7 +2396,7 @@ builtin_input(PyObject *self, PyObject *args) /* If we're interactive, use (GNU) readline */ if (tty) { PyObject *po = NULL; - char *prompt; + char *promptstr; char *s = NULL; PyObject *stdin_encoding = NULL, *stdin_errors = NULL; PyObject *stdout_encoding = NULL, *stdout_errors = NULL; @@ -1752,7 +2419,7 @@ builtin_input(PyObject *self, PyObject *args) PyErr_Clear(); else Py_DECREF(tmp); - if (promptarg != NULL) { + if (prompt != NULL) { /* We have a prompt, encode it as stdout would */ char *stdout_encoding_str, *stdout_errors_str; PyObject *stringpo; @@ -1764,7 +2431,7 @@ builtin_input(PyObject *self, PyObject *args) stdout_errors_str = _PyUnicode_AsString(stdout_errors); if (!stdout_encoding_str || !stdout_errors_str) goto _readline_errors; - stringpo = PyObject_Str(promptarg); + stringpo = PyObject_Str(prompt); if (stringpo == NULL) goto _readline_errors; po = PyUnicode_AsEncodedString(stringpo, @@ -1774,15 +2441,15 @@ builtin_input(PyObject *self, PyObject *args) Py_CLEAR(stringpo); if (po == NULL) goto _readline_errors; - prompt = PyBytes_AsString(po); - if (prompt == NULL) + promptstr = PyBytes_AsString(po); + if (promptstr == NULL) goto _readline_errors; } else { po = NULL; - prompt = ""; + promptstr = ""; } - s = PyOS_Readline(stdin, stdout, prompt); + s = PyOS_Readline(stdin, stdout, promptstr); if (s == NULL) { PyErr_CheckSignals(); if (!PyErr_Occurred()) @@ -1824,8 +2491,8 @@ builtin_input(PyObject *self, PyObject *args) } /* Fallback if we're not interactive */ - if (promptarg != NULL) { - if (PyFile_WriteObject(promptarg, fout, Py_PRINT_RAW) != 0) + if (prompt != NULL) { + if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0) return NULL; } tmp = _PyObject_CallMethodId(fout, &PyId_flush, ""); @@ -1836,28 +2503,40 @@ builtin_input(PyObject *self, PyObject *args) return PyFile_GetLine(fin, -1); } -PyDoc_STRVAR(input_doc, -"input([prompt]) -> string\n\ -\n\ -Read a string from standard input. The trailing newline is stripped.\n\ -If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.\n\ -On Unix, GNU readline is used if enabled. The prompt string, if given,\n\ -is printed without a trailing newline before reading."); +/*[clinic input] +repr as builtin_repr + + obj: 'O' + / + +Return the canonical string representation of the object. + +For many object types, including most builtins, eval(repr(obj)) == obj. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_repr__doc__, +"repr($module, obj, /)\n" +"--\n" +"\n" +"Return the canonical string representation of the object.\n" +"\n" +"For many object types, including most builtins, eval(repr(obj)) == obj."); + +#define BUILTIN_REPR_METHODDEF \ + {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__}, static PyObject * -builtin_repr(PyObject *self, PyObject *v) +builtin_repr(PyModuleDef *module, PyObject *obj) +/*[clinic end generated code: output=988980120f39e2fa input=a2bca0f38a5a924d]*/ { - return PyObject_Repr(v); + return PyObject_Repr(obj); } -PyDoc_STRVAR(repr_doc, -"repr(object) -> string\n\ -\n\ -Return the canonical string representation of the object.\n\ -For most object types, eval(repr(object)) == object."); - +/* AC: cannot convert yet, as needs PEP 457 group support in inspect + * or a semantic change to accept None for "ndigits" + */ static PyObject * builtin_round(PyObject *self, PyObject *args, PyObject *kwds) { @@ -1899,6 +2578,35 @@ 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 + * the initially generated signature with a custom implementation. + */ +/* [disabled clinic input] +sorted as builtin_sorted + + iterable as seq: 'O' + key as keyfunc: 'O' = None + reverse: 'O' = False + +Return a new list containing all items from the iterable in ascending order. + +A custom key function can be supplied to customise the sort order, and the +reverse flag can be set to request the result in descending order. +[end disabled clinic input]*/ + +PyDoc_STRVAR(builtin_sorted__doc__, +"sorted($module, iterable, key=None, reverse=False)\n" +"--\n" +"\n" +"Return a new list containing all items from the iterable in ascending order.\n" +"\n" +"A custom key function can be supplied to customise the sort order, and the\n" +"reverse flag can be set to request the result in descending order."); + +#define BUILTIN_SORTED_METHODDEF \ + {"sorted", (PyCFunction)builtin_sorted, METH_VARARGS|METH_KEYWORDS, builtin_sorted__doc__}, + static PyObject * builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds) { @@ -1940,9 +2648,8 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds) return newlist; } -PyDoc_STRVAR(sorted_doc, -"sorted(iterable, key=None, reverse=False) --> new sorted list"); +/* AC: cannot convert yet, as needs PEP 457 group support in inspect */ static PyObject * builtin_vars(PyObject *self, PyObject *args) { @@ -1974,17 +2681,62 @@ PyDoc_STRVAR(vars_doc, Without arguments, equivalent to locals().\n\ With an argument, equivalent to object.__dict__."); -static PyObject* -builtin_sum(PyObject *self, PyObject *args) + +/*[clinic input] +sum as builtin_sum + + iterable: 'O' + start: object(c_default="NULL") = 0 + / + +Return the sum of a 'start' value (default: 0) plus an iterable of numbers + +When the iterable is empty, return the start value. +This function is intended specifically for use with numeric values and may +reject non-numeric types. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_sum__doc__, +"sum($module, iterable, start=0, /)\n" +"--\n" +"\n" +"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n" +"\n" +"When the iterable is empty, return the start value.\n" +"This function is intended specifically for use with numeric values and may\n" +"reject non-numeric types."); + +#define BUILTIN_SUM_METHODDEF \ + {"sum", (PyCFunction)builtin_sum, METH_VARARGS, builtin_sum__doc__}, + +static PyObject * +builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start); + +static PyObject * +builtin_sum(PyModuleDef *module, PyObject *args) { - PyObject *seq; - PyObject *result = NULL; - PyObject *temp, *item, *iter; + PyObject *return_value = NULL; + PyObject *iterable; + PyObject *start = NULL; + + if (!PyArg_UnpackTuple(args, "sum", + 1, 2, + &iterable, &start)) + goto exit; + return_value = builtin_sum_impl(module, iterable, start); + +exit: + return return_value; +} - if (!PyArg_UnpackTuple(args, "sum", 1, 2, &seq, &result)) - return NULL; +static PyObject * +builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start) +/*[clinic end generated code: output=b42652a0d5f64f6b input=90ae7a242cfcf025]*/ +{ + PyObject *result = start; + PyObject *temp, *item, *iter; - iter = PyObject_GetIter(seq); + iter = PyObject_GetIter(iterable); if (iter == NULL) return NULL; @@ -2014,7 +2766,6 @@ builtin_sum(PyObject *self, PyObject *args) Py_DECREF(iter); return NULL; } - Py_INCREF(result); } @@ -2140,62 +2891,126 @@ builtin_sum(PyObject *self, PyObject *args) return result; } -PyDoc_STRVAR(sum_doc, -"sum(iterable[, start]) -> value\n\ -\n\ -Return the sum of an iterable of numbers (NOT strings) plus the value\n\ -of parameter 'start' (which defaults to 0). When the iterable is\n\ -empty, return start."); +/*[clinic input] +isinstance as builtin_isinstance + + obj: 'O' + class_or_tuple: 'O' + / + +Return whether an object is an instance of a class or of a subclass thereof. + +A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to +check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B) +or ...`` etc. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_isinstance__doc__, +"isinstance($module, obj, class_or_tuple, /)\n" +"--\n" +"\n" +"Return whether an object is an instance of a class or of a subclass thereof.\n" +"\n" +"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n" +"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n" +"or ...`` etc."); + +#define BUILTIN_ISINSTANCE_METHODDEF \ + {"isinstance", (PyCFunction)builtin_isinstance, METH_VARARGS, builtin_isinstance__doc__}, + +static PyObject * +builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, PyObject *class_or_tuple); static PyObject * -builtin_isinstance(PyObject *self, PyObject *args) +builtin_isinstance(PyModuleDef *module, PyObject *args) { - PyObject *inst; - PyObject *cls; - int retval; + PyObject *return_value = NULL; + PyObject *obj; + PyObject *class_or_tuple; + + if (!PyArg_UnpackTuple(args, "isinstance", + 2, 2, + &obj, &class_or_tuple)) + goto exit; + return_value = builtin_isinstance_impl(module, obj, class_or_tuple); + +exit: + return return_value; +} - if (!PyArg_UnpackTuple(args, "isinstance", 2, 2, &inst, &cls)) - return NULL; +static PyObject * +builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, PyObject *class_or_tuple) +/*[clinic end generated code: output=847df57fef8ddea7 input=cf9eb0ad6bb9bad6]*/ +{ + int retval; - retval = PyObject_IsInstance(inst, cls); + retval = PyObject_IsInstance(obj, class_or_tuple); if (retval < 0) return NULL; return PyBool_FromLong(retval); } -PyDoc_STRVAR(isinstance_doc, -"isinstance(object, class-or-type-or-tuple) -> bool\n\ -\n\ -Return whether an object is an instance of a class or of a subclass thereof.\n\ -With a type as second argument, return whether that is the object's type.\n\ -The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for\n\ -isinstance(x, A) or isinstance(x, B) or ... (etc.)."); +/*[clinic input] +issubclass as builtin_issubclass + + cls: 'O' + class_or_tuple: 'O' + / + +Return whether 'cls' is a derived from another class or is the same class. + +A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to +check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B) +or ...`` etc. +[clinic start generated code]*/ + +PyDoc_STRVAR(builtin_issubclass__doc__, +"issubclass($module, cls, class_or_tuple, /)\n" +"--\n" +"\n" +"Return whether \'cls\' is a derived from another class or is the same class.\n" +"\n" +"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n" +"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n" +"or ...`` etc."); + +#define BUILTIN_ISSUBCLASS_METHODDEF \ + {"issubclass", (PyCFunction)builtin_issubclass, METH_VARARGS, builtin_issubclass__doc__}, static PyObject * -builtin_issubclass(PyObject *self, PyObject *args) +builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, PyObject *class_or_tuple); + +static PyObject * +builtin_issubclass(PyModuleDef *module, PyObject *args) { - PyObject *derived; + PyObject *return_value = NULL; PyObject *cls; - int retval; + PyObject *class_or_tuple; - if (!PyArg_UnpackTuple(args, "issubclass", 2, 2, &derived, &cls)) - return NULL; + if (!PyArg_UnpackTuple(args, "issubclass", + 2, 2, + &cls, &class_or_tuple)) + goto exit; + return_value = builtin_issubclass_impl(module, cls, class_or_tuple); + +exit: + return return_value; +} - retval = PyObject_IsSubclass(derived, cls); +static PyObject * +builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, PyObject *class_or_tuple) +/*[clinic end generated code: output=a0f8c03692e35474 input=923d03fa41fc352a]*/ +{ + int retval; + + retval = PyObject_IsSubclass(cls, class_or_tuple); if (retval < 0) return NULL; return PyBool_FromLong(retval); } -PyDoc_STRVAR(issubclass_doc, -"issubclass(C, B) -> bool\n\ -\n\ -Return whether class C is a subclass (i.e., a derived class) of class B.\n\ -When using a tuple as the second argument issubclass(X, (A, B, ...)),\n\ -is a shortcut for issubclass(X, A) or issubclass(X, B) or ... (etc.)."); - typedef struct { PyObject_HEAD @@ -2390,44 +3205,44 @@ static PyMethodDef builtin_methods[] = { {"__build_class__", (PyCFunction)builtin___build_class__, METH_VARARGS | METH_KEYWORDS, build_class_doc}, {"__import__", (PyCFunction)builtin___import__, METH_VARARGS | METH_KEYWORDS, import_doc}, - {"abs", builtin_abs, METH_O, abs_doc}, - {"all", builtin_all, METH_O, all_doc}, - {"any", builtin_any, METH_O, any_doc}, - {"ascii", builtin_ascii, METH_O, ascii_doc}, - {"bin", builtin_bin, METH_O, bin_doc}, - {"callable", builtin_callable, METH_O, callable_doc}, - {"chr", builtin_chr, METH_VARARGS, chr_doc}, - {"compile", (PyCFunction)builtin_compile, METH_VARARGS | METH_KEYWORDS, compile_doc}, - {"delattr", builtin_delattr, METH_VARARGS, delattr_doc}, + BUILTIN_ABS_METHODDEF + BUILTIN_ALL_METHODDEF + BUILTIN_ANY_METHODDEF + BUILTIN_ASCII_METHODDEF + BUILTIN_BIN_METHODDEF + BUILTIN_CALLABLE_METHODDEF + BUILTIN_CHR_METHODDEF + BUILTIN_COMPILE_METHODDEF + BUILTIN_DELATTR_METHODDEF {"dir", builtin_dir, METH_VARARGS, dir_doc}, - {"divmod", builtin_divmod, METH_VARARGS, divmod_doc}, - {"eval", builtin_eval, METH_VARARGS, eval_doc}, - {"exec", builtin_exec, METH_VARARGS, exec_doc}, - {"format", builtin_format, METH_VARARGS, format_doc}, + BUILTIN_DIVMOD_METHODDEF + BUILTIN_EVAL_METHODDEF + BUILTIN_EXEC_METHODDEF + BUILTIN_FORMAT_METHODDEF {"getattr", builtin_getattr, METH_VARARGS, getattr_doc}, - {"globals", (PyCFunction)builtin_globals, METH_NOARGS, globals_doc}, - {"hasattr", builtin_hasattr, METH_VARARGS, hasattr_doc}, - {"hash", builtin_hash, METH_O, hash_doc}, - {"hex", builtin_hex, METH_O, hex_doc}, - {"id", builtin_id, METH_O, id_doc}, - {"input", builtin_input, METH_VARARGS, input_doc}, - {"isinstance", builtin_isinstance, METH_VARARGS, isinstance_doc}, - {"issubclass", builtin_issubclass, METH_VARARGS, issubclass_doc}, + BUILTIN_GLOBALS_METHODDEF + BUILTIN_HASATTR_METHODDEF + BUILTIN_HASH_METHODDEF + BUILTIN_HEX_METHODDEF + BUILTIN_ID_METHODDEF + BUILTIN_INPUT_METHODDEF + BUILTIN_ISINSTANCE_METHODDEF + BUILTIN_ISSUBCLASS_METHODDEF {"iter", builtin_iter, METH_VARARGS, iter_doc}, - {"len", builtin_len, METH_O, len_doc}, - {"locals", (PyCFunction)builtin_locals, METH_NOARGS, locals_doc}, + BUILTIN_LEN_METHODDEF + BUILTIN_LOCALS_METHODDEF {"max", (PyCFunction)builtin_max, METH_VARARGS | METH_KEYWORDS, max_doc}, {"min", (PyCFunction)builtin_min, METH_VARARGS | METH_KEYWORDS, min_doc}, {"next", (PyCFunction)builtin_next, METH_VARARGS, next_doc}, - {"oct", builtin_oct, METH_O, oct_doc}, - {"ord", builtin_ord, METH_O, ord_doc}, - {"pow", builtin_pow, METH_VARARGS, pow_doc}, + BUILTIN_OCT_METHODDEF + BUILTIN_ORD_METHODDEF + BUILTIN_POW_METHODDEF {"print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc}, - {"repr", builtin_repr, METH_O, repr_doc}, + BUILTIN_REPR_METHODDEF {"round", (PyCFunction)builtin_round, METH_VARARGS | METH_KEYWORDS, round_doc}, - {"setattr", builtin_setattr, METH_VARARGS, setattr_doc}, - {"sorted", (PyCFunction)builtin_sorted, METH_VARARGS | METH_KEYWORDS, sorted_doc}, - {"sum", builtin_sum, METH_VARARGS, sum_doc}, + BUILTIN_SETATTR_METHODDEF + BUILTIN_SORTED_METHODDEF + BUILTIN_SUM_METHODDEF {"vars", builtin_vars, METH_VARARGS, vars_doc}, {NULL, NULL}, }; -- cgit v1.2.1 From b6c677f13497ce8dabc8aad7fb272b09dfeccb56 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 6 Sep 2014 20:07:17 +0300 Subject: Issue #22215: Now ValueError is raised instead of TypeError when str or bytes argument contains not permitted null character or byte. --- Python/bltinmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index cbadc12218..068398fb9b 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -745,8 +745,8 @@ source_as_string(PyObject *cmd, char *funcname, char *what, PyCompilerFlags *cf) return NULL; } - if (strlen(str) != (size_t)size) { - PyErr_SetString(PyExc_TypeError, + if (strlen(str) != (size_t)size) { + PyErr_SetString(PyExc_ValueError, "source code string cannot contain null bytes"); return NULL; } -- cgit v1.2.1 From 64409f21935d3ffeb43ca8564921c2f96b842843 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 18 Mar 2015 15:02:06 +0100 Subject: Initialize variables to prevent GCC warnings --- Python/bltinmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index f9bb388b5a..4f61d1e710 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -53,7 +53,7 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *cell; PyObject *cls = NULL; Py_ssize_t nargs; - int isclass; + int isclass = 0; /* initialize to prevent gcc warning */ assert(args != NULL); if (!PyTuple_Check(args)) { -- cgit v1.2.1 From 970e566ca7317a2fa90d57de73aec7216995691f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 3 Apr 2015 23:53:51 +0300 Subject: Issue #23501: Argumen Clinic now generates code into separate files by default. --- Python/bltinmodule.c | 715 +++------------------------------------------------ 1 file changed, 31 insertions(+), 684 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 4f61d1e710..e733485111 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -46,6 +46,8 @@ _Py_IDENTIFIER(stdin); _Py_IDENTIFIER(stdout); _Py_IDENTIFIER(stderr); +#include "clinic/bltinmodule.c.h" + /* AC: cannot convert yet, waiting for *args support */ static PyObject * builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) @@ -239,18 +241,9 @@ abs as builtin_abs Return the absolute value of the argument. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_abs__doc__, -"abs($module, x, /)\n" -"--\n" -"\n" -"Return the absolute value of the argument."); - -#define BUILTIN_ABS_METHODDEF \ - {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__}, - static PyObject * builtin_abs(PyModuleDef *module, PyObject *x) -/*[clinic end generated code: output=f85095528ce7e2e5 input=aa29cc07869b4732]*/ +/*[clinic end generated code: output=6833047c493ecea2 input=aa29cc07869b4732]*/ { return PyNumber_Absolute(x); } @@ -266,20 +259,9 @@ Return True if bool(x) is True for all values x in the iterable. If the iterable is empty, return True. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_all__doc__, -"all($module, iterable, /)\n" -"--\n" -"\n" -"Return True if bool(x) is True for all values x in the iterable.\n" -"\n" -"If the iterable is empty, return True."); - -#define BUILTIN_ALL_METHODDEF \ - {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__}, - static PyObject * builtin_all(PyModuleDef *module, PyObject *iterable) -/*[clinic end generated code: output=d001db739ba83b46 input=dd506dc9998d42bd]*/ +/*[clinic end generated code: output=089e6d1b7bde27b1 input=dd506dc9998d42bd]*/ { PyObject *it, *item; PyObject *(*iternext)(PyObject *); @@ -326,20 +308,9 @@ Return True if bool(x) is True for any x in the iterable. If the iterable is empty, return False. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_any__doc__, -"any($module, iterable, /)\n" -"--\n" -"\n" -"Return True if bool(x) is True for any x in the iterable.\n" -"\n" -"If the iterable is empty, return False."); - -#define BUILTIN_ANY_METHODDEF \ - {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__}, - static PyObject * builtin_any(PyModuleDef *module, PyObject *iterable) -/*[clinic end generated code: output=3a4b6dbe6a0d6f61 input=8fe8460f3fbbced8]*/ +/*[clinic end generated code: output=1be994b2c2307492 input=8fe8460f3fbbced8]*/ { PyObject *it, *item; PyObject *(*iternext)(PyObject *); @@ -389,23 +360,9 @@ repr() using \\x, \\u or \\U escapes. This generates a string similar to that returned by repr() in Python 2. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_ascii__doc__, -"ascii($module, obj, /)\n" -"--\n" -"\n" -"Return an ASCII-only representation of an object.\n" -"\n" -"As repr(), return a string containing a printable representation of an\n" -"object, but escape the non-ASCII characters in the string returned by\n" -"repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n" -"to that returned by repr() in Python 2."); - -#define BUILTIN_ASCII_METHODDEF \ - {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__}, - static PyObject * builtin_ascii(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=f0e6754154c2d30b input=0cbdc1420a306325]*/ +/*[clinic end generated code: output=d4e862c48af2a933 input=0cbdc1420a306325]*/ { return PyObject_ASCII(obj); } @@ -423,21 +380,9 @@ Return the binary representation of an integer. '0b1010101010101010101010' [clinic start generated code]*/ -PyDoc_STRVAR(builtin_bin__doc__, -"bin($module, number, /)\n" -"--\n" -"\n" -"Return the binary representation of an integer.\n" -"\n" -" >>> bin(2796202)\n" -" \'0b1010101010101010101010\'"); - -#define BUILTIN_BIN_METHODDEF \ - {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__}, - static PyObject * builtin_bin(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=18fed0e943650da1 input=2a6362ae9a9c9203]*/ +/*[clinic end generated code: output=25ee26c6cf3bbb54 input=2a6362ae9a9c9203]*/ { return PyNumber_ToBase(number, 2); } @@ -455,21 +400,9 @@ Note that classes are callable, as are instances of classes with a __call__() method. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_callable__doc__, -"callable($module, obj, /)\n" -"--\n" -"\n" -"Return whether the object is callable (i.e., some kind of function).\n" -"\n" -"Note that classes are callable, as are instances of classes with a\n" -"__call__() method."); - -#define BUILTIN_CALLABLE_METHODDEF \ - {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__}, - static PyObject * builtin_callable(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=b3a92cbe635f32af input=bb3bb528fffdade4]*/ +/*[clinic end generated code: output=f4df2ce92364b656 input=bb3bb528fffdade4]*/ { return PyBool_FromLong((long)PyCallable_Check(obj)); } @@ -640,40 +573,9 @@ Return value.__format__(format_spec) format_spec defaults to the empty string [clinic start generated code]*/ -PyDoc_STRVAR(builtin_format__doc__, -"format($module, value, format_spec=\'\', /)\n" -"--\n" -"\n" -"Return value.__format__(format_spec)\n" -"\n" -"format_spec defaults to the empty string"); - -#define BUILTIN_FORMAT_METHODDEF \ - {"format", (PyCFunction)builtin_format, METH_VARARGS, builtin_format__doc__}, - -static PyObject * -builtin_format_impl(PyModuleDef *module, PyObject *value, PyObject *format_spec); - -static PyObject * -builtin_format(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *value; - PyObject *format_spec = NULL; - - if (!PyArg_ParseTuple(args, - "O|U:format", - &value, &format_spec)) - goto exit; - return_value = builtin_format_impl(module, value, format_spec); - -exit: - return return_value; -} - static PyObject * builtin_format_impl(PyModuleDef *module, PyObject *value, PyObject *format_spec) -/*[clinic end generated code: output=39723a58c72e8871 input=e23f2f11e0098c64]*/ +/*[clinic end generated code: output=fae3e927cc715466 input=e23f2f11e0098c64]*/ { return PyObject_Format(value, format_spec); } @@ -687,37 +589,9 @@ chr as builtin_chr Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_chr__doc__, -"chr($module, i, /)\n" -"--\n" -"\n" -"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); - -#define BUILTIN_CHR_METHODDEF \ - {"chr", (PyCFunction)builtin_chr, METH_VARARGS, builtin_chr__doc__}, - -static PyObject * -builtin_chr_impl(PyModuleDef *module, int i); - -static PyObject * -builtin_chr(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int i; - - if (!PyArg_ParseTuple(args, - "i:chr", - &i)) - goto exit; - return_value = builtin_chr_impl(module, i); - -exit: - return return_value; -} - static PyObject * builtin_chr_impl(PyModuleDef *module, int i) -/*[clinic end generated code: output=4d6bbe948f56e2ae input=9b1ced29615adf66]*/ +/*[clinic end generated code: output=67fe4d87e690f373 input=9b1ced29615adf66]*/ { return PyUnicode_FromOrdinal(i); } @@ -779,55 +653,9 @@ compile; if absent or zero these statements do influence the compilation, in addition to any features explicitly specified. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_compile__doc__, -"compile($module, /, source, filename, mode, flags=0, dont_inherit=0,\n" -" optimize=-1)\n" -"--\n" -"\n" -"Compile source into a code object that can be executed by exec() or eval().\n" -"\n" -"The source code may represent a Python module, statement or expression.\n" -"The filename will be used for run-time error messages.\n" -"The mode must be \'exec\' to compile a module, \'single\' to compile a\n" -"single (interactive) statement, or \'eval\' to compile an expression.\n" -"The flags argument, if present, controls which future statements influence\n" -"the compilation of the code.\n" -"The dont_inherit argument, if non-zero, stops the compilation inheriting\n" -"the effects of any future statements in effect in the code calling\n" -"compile; if absent or zero these statements do influence the compilation,\n" -"in addition to any features explicitly specified."); - -#define BUILTIN_COMPILE_METHODDEF \ - {"compile", (PyCFunction)builtin_compile, METH_VARARGS|METH_KEYWORDS, builtin_compile__doc__}, - -static PyObject * -builtin_compile_impl(PyModuleDef *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, int optimize); - -static PyObject * -builtin_compile(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL}; - PyObject *source; - PyObject *filename; - const char *mode; - int flags = 0; - int dont_inherit = 0; - int optimize = -1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "OO&s|iii:compile", _keywords, - &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) - goto exit; - return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize); - -exit: - return return_value; -} - static PyObject * builtin_compile_impl(PyModuleDef *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, int optimize) -/*[clinic end generated code: output=c72d197809d178fc input=c6212a9d21472f7e]*/ +/*[clinic end generated code: output=4f41a315386bab9f input=c6212a9d21472f7e]*/ { Py_buffer view = {NULL, NULL}; const char *str; @@ -951,38 +779,9 @@ divmod as builtin_divmod Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_divmod__doc__, -"divmod($module, x, y, /)\n" -"--\n" -"\n" -"Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."); - -#define BUILTIN_DIVMOD_METHODDEF \ - {"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__}, - -static PyObject * -builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y); - -static PyObject * -builtin_divmod(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *x; - PyObject *y; - - if (!PyArg_UnpackTuple(args, "divmod", - 2, 2, - &x, &y)) - goto exit; - return_value = builtin_divmod_impl(module, x, y); - -exit: - return return_value; -} - static PyObject * builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y) -/*[clinic end generated code: output=77e8d408b1338886 input=c9c617b7bb74c615]*/ +/*[clinic end generated code: output=9ad0076120ebf9ac input=c9c617b7bb74c615]*/ { return PyNumber_Divmod(x, y); } @@ -1005,45 +804,9 @@ defaulting to the current globals and locals. If only globals is given, locals defaults to it. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_eval__doc__, -"eval($module, source, globals=None, locals=None, /)\n" -"--\n" -"\n" -"Evaluate the given source in the context of globals and locals.\n" -"\n" -"The source may be a string representing a Python expression\n" -"or a code object as returned by compile().\n" -"The globals must be a dictionary and locals can be any mapping,\n" -"defaulting to the current globals and locals.\n" -"If only globals is given, locals defaults to it."); - -#define BUILTIN_EVAL_METHODDEF \ - {"eval", (PyCFunction)builtin_eval, METH_VARARGS, builtin_eval__doc__}, - -static PyObject * -builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals); - -static PyObject * -builtin_eval(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *source; - PyObject *globals = Py_None; - PyObject *locals = Py_None; - - if (!PyArg_UnpackTuple(args, "eval", - 1, 3, - &source, &globals, &locals)) - goto exit; - return_value = builtin_eval_impl(module, source, globals, locals); - -exit: - return return_value; -} - static PyObject * builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals) -/*[clinic end generated code: output=644fd59012538ce6 input=31e42c1d2125b50b]*/ +/*[clinic end generated code: output=90642b79dd8b08d6 input=31e42c1d2125b50b]*/ { PyObject *result, *tmp = NULL; Py_buffer view = {NULL, NULL}; @@ -1125,45 +888,9 @@ defaulting to the current globals and locals. If only globals is given, locals defaults to it. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_exec__doc__, -"exec($module, source, globals=None, locals=None, /)\n" -"--\n" -"\n" -"Execute the given source in the context of globals and locals.\n" -"\n" -"The source may be a string representing one or more Python statements\n" -"or a code object as returned by compile().\n" -"The globals must be a dictionary and locals can be any mapping,\n" -"defaulting to the current globals and locals.\n" -"If only globals is given, locals defaults to it."); - -#define BUILTIN_EXEC_METHODDEF \ - {"exec", (PyCFunction)builtin_exec, METH_VARARGS, builtin_exec__doc__}, - -static PyObject * -builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals); - -static PyObject * -builtin_exec(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *source; - PyObject *globals = Py_None; - PyObject *locals = Py_None; - - if (!PyArg_UnpackTuple(args, "exec", - 1, 3, - &source, &globals, &locals)) - goto exit; - return_value = builtin_exec_impl(module, source, globals, locals); - -exit: - return return_value; -} - static PyObject * builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals) -/*[clinic end generated code: output=0281b48bfa8e3c87 input=536e057b5e00d89e]*/ +/*[clinic end generated code: output=e8e0bbcde826a048 input=536e057b5e00d89e]*/ { PyObject *v; @@ -1275,30 +1002,9 @@ NOTE: Updates to this dictionary *will* affect name lookups in the current global scope and vice-versa. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_globals__doc__, -"globals($module, /)\n" -"--\n" -"\n" -"Return the dictionary containing the current scope\'s global variables.\n" -"\n" -"NOTE: Updates to this dictionary *will* affect name lookups in the current\n" -"global scope and vice-versa."); - -#define BUILTIN_GLOBALS_METHODDEF \ - {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__}, - -static PyObject * -builtin_globals_impl(PyModuleDef *module); - -static PyObject * -builtin_globals(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return builtin_globals_impl(module); -} - static PyObject * builtin_globals_impl(PyModuleDef *module) -/*[clinic end generated code: output=048640f58b1f20ad input=9327576f92bb48ba]*/ +/*[clinic end generated code: output=4958645e96dd8138 input=9327576f92bb48ba]*/ { PyObject *d; @@ -1320,40 +1026,9 @@ Return whether the object has an attribute with the given name. This is done by calling getattr(obj, name) and catching AttributeError. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_hasattr__doc__, -"hasattr($module, obj, name, /)\n" -"--\n" -"\n" -"Return whether the object has an attribute with the given name.\n" -"\n" -"This is done by calling getattr(obj, name) and catching AttributeError."); - -#define BUILTIN_HASATTR_METHODDEF \ - {"hasattr", (PyCFunction)builtin_hasattr, METH_VARARGS, builtin_hasattr__doc__}, - -static PyObject * -builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name); - -static PyObject * -builtin_hasattr(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *obj; - PyObject *name; - - if (!PyArg_UnpackTuple(args, "hasattr", - 2, 2, - &obj, &name)) - goto exit; - return_value = builtin_hasattr_impl(module, obj, name); - -exit: - return return_value; -} - static PyObject * builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) -/*[clinic end generated code: output=e0bd996ef73d1217 input=b50bad5f739ea10d]*/ +/*[clinic end generated code: output=81154fdd63634696 input=b50bad5f739ea10d]*/ { PyObject *v; @@ -1392,21 +1067,9 @@ This is guaranteed to be unique among simultaneously existing objects. (CPython uses the object's memory address.) [clinic start generated code]*/ -PyDoc_STRVAR(builtin_id__doc__, -"id($module, obj, /)\n" -"--\n" -"\n" -"Return the identity of an object.\n" -"\n" -"This is guaranteed to be unique among simultaneously existing objects.\n" -"(CPython uses the object\'s memory address.)"); - -#define BUILTIN_ID_METHODDEF \ - {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__}, - static PyObject * builtin_id(PyModuleDef *self, PyObject *v) -/*[clinic end generated code: output=f54da09c91992e63 input=a1f988d98357341d]*/ +/*[clinic end generated code: output=0aa640785f697f65 input=a1f988d98357341d]*/ { return PyLong_FromVoidPtr(v); } @@ -1639,41 +1302,9 @@ Sets the named attribute on the given object to the specified value. setattr(x, 'y', v) is equivalent to ``x.y = v'' [clinic start generated code]*/ -PyDoc_STRVAR(builtin_setattr__doc__, -"setattr($module, obj, name, value, /)\n" -"--\n" -"\n" -"Sets the named attribute on the given object to the specified value.\n" -"\n" -"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'"); - -#define BUILTIN_SETATTR_METHODDEF \ - {"setattr", (PyCFunction)builtin_setattr, METH_VARARGS, builtin_setattr__doc__}, - -static PyObject * -builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, PyObject *value); - -static PyObject * -builtin_setattr(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *obj; - PyObject *name; - PyObject *value; - - if (!PyArg_UnpackTuple(args, "setattr", - 3, 3, - &obj, &name, &value)) - goto exit; - return_value = builtin_setattr_impl(module, obj, name, value); - -exit: - return return_value; -} - static PyObject * builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, PyObject *value) -/*[clinic end generated code: output=4336dcbbf7691d2d input=fbe7e53403116b93]*/ +/*[clinic end generated code: output=c5e0a3a3971333ed input=fbe7e53403116b93]*/ { if (PyObject_SetAttr(obj, name, value) != 0) return NULL; @@ -1694,40 +1325,9 @@ Deletes the named attribute from the given object. delattr(x, 'y') is equivalent to ``del x.y'' [clinic start generated code]*/ -PyDoc_STRVAR(builtin_delattr__doc__, -"delattr($module, obj, name, /)\n" -"--\n" -"\n" -"Deletes the named attribute from the given object.\n" -"\n" -"delattr(x, \'y\') is equivalent to ``del x.y\'\'"); - -#define BUILTIN_DELATTR_METHODDEF \ - {"delattr", (PyCFunction)builtin_delattr, METH_VARARGS, builtin_delattr__doc__}, - -static PyObject * -builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name); - -static PyObject * -builtin_delattr(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *obj; - PyObject *name; - - if (!PyArg_UnpackTuple(args, "delattr", - 2, 2, - &obj, &name)) - goto exit; - return_value = builtin_delattr_impl(module, obj, name); - -exit: - return return_value; -} - static PyObject * builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) -/*[clinic end generated code: output=319c2d884aa769cf input=647af2ce9183a823]*/ +/*[clinic end generated code: output=ef653e698a0b4187 input=647af2ce9183a823]*/ { if (PyObject_SetAttr(obj, name, (PyObject *)NULL) != 0) return NULL; @@ -1748,21 +1348,9 @@ Two objects that compare equal must also have the same hash value, but the reverse is not necessarily true. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_hash__doc__, -"hash($module, obj, /)\n" -"--\n" -"\n" -"Return the hash value for the given object.\n" -"\n" -"Two objects that compare equal must also have the same hash value, but the\n" -"reverse is not necessarily true."); - -#define BUILTIN_HASH_METHODDEF \ - {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__}, - static PyObject * builtin_hash(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=1ec467611c13468b input=ccc4d2b9a351df4e]*/ +/*[clinic end generated code: output=1f32ff154c1f751a input=ccc4d2b9a351df4e]*/ { Py_hash_t x; @@ -1785,21 +1373,9 @@ Return the hexadecimal representation of an integer. '0xc0ffee' [clinic start generated code]*/ -PyDoc_STRVAR(builtin_hex__doc__, -"hex($module, number, /)\n" -"--\n" -"\n" -"Return the hexadecimal representation of an integer.\n" -"\n" -" >>> hex(12648430)\n" -" \'0xc0ffee\'"); - -#define BUILTIN_HEX_METHODDEF \ - {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__}, - static PyObject * builtin_hex(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=f18e9439aeaa2c6c input=e816200b0a728ebe]*/ +/*[clinic end generated code: output=618489ce3cbc5858 input=e816200b0a728ebe]*/ { return PyNumber_ToBase(number, 16); } @@ -1841,18 +1417,9 @@ len as builtin_len Return the number of items in a container. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_len__doc__, -"len($module, obj, /)\n" -"--\n" -"\n" -"Return the number of items in a container."); - -#define BUILTIN_LEN_METHODDEF \ - {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__}, - static PyObject * builtin_len(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=5a38b0db40761705 input=2e5ff15db9a2de22]*/ +/*[clinic end generated code: output=8e5837b6f81d915b input=2e5ff15db9a2de22]*/ { Py_ssize_t res; @@ -1873,31 +1440,9 @@ the local scope and vice-versa is *implementation dependent* and not covered by any backwards compatibility guarantees. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_locals__doc__, -"locals($module, /)\n" -"--\n" -"\n" -"Return a dictionary containing the current scope\'s local variables.\n" -"\n" -"NOTE: Whether or not updates to this dictionary will affect name lookups in\n" -"the local scope and vice-versa is *implementation dependent* and not\n" -"covered by any backwards compatibility guarantees."); - -#define BUILTIN_LOCALS_METHODDEF \ - {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__}, - -static PyObject * -builtin_locals_impl(PyModuleDef *module); - -static PyObject * -builtin_locals(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return builtin_locals_impl(module); -} - static PyObject * builtin_locals_impl(PyModuleDef *module) -/*[clinic end generated code: output=8ac52522924346e2 input=7874018d478d5c4b]*/ +/*[clinic end generated code: output=8b5a41f12e19d13a input=7874018d478d5c4b]*/ { PyObject *d; @@ -2054,21 +1599,9 @@ Return the octal representation of an integer. '0o1234567' [clinic start generated code]*/ -PyDoc_STRVAR(builtin_oct__doc__, -"oct($module, number, /)\n" -"--\n" -"\n" -"Return the octal representation of an integer.\n" -"\n" -" >>> oct(342391)\n" -" \'0o1234567\'"); - -#define BUILTIN_OCT_METHODDEF \ - {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__}, - static PyObject * builtin_oct(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=b99234d1d70a6673 input=a3a372b521b3dd13]*/ +/*[clinic end generated code: output=18f701bc6d8f804a input=a3a372b521b3dd13]*/ { return PyNumber_ToBase(number, 8); } @@ -2083,18 +1616,9 @@ ord as builtin_ord Return the Unicode code point for a one-character string. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_ord__doc__, -"ord($module, c, /)\n" -"--\n" -"\n" -"Return the Unicode code point for a one-character string."); - -#define BUILTIN_ORD_METHODDEF \ - {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__}, - static PyObject * builtin_ord(PyModuleDef *module, PyObject *c) -/*[clinic end generated code: output=a8466d23bd76db3f input=762355f87451efa3]*/ +/*[clinic end generated code: output=04fd27272d9462f6 input=762355f87451efa3]*/ { long ord; Py_ssize_t size; @@ -2152,42 +1676,9 @@ Some types, such as ints, are able to use a more efficient algorithm when invoked using the three argument form. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_pow__doc__, -"pow($module, x, y, z=None, /)\n" -"--\n" -"\n" -"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n" -"\n" -"Some types, such as ints, are able to use a more efficient algorithm when\n" -"invoked using the three argument form."); - -#define BUILTIN_POW_METHODDEF \ - {"pow", (PyCFunction)builtin_pow, METH_VARARGS, builtin_pow__doc__}, - -static PyObject * -builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z); - -static PyObject * -builtin_pow(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *x; - PyObject *y; - PyObject *z = Py_None; - - if (!PyArg_UnpackTuple(args, "pow", - 2, 3, - &x, &y, &z)) - goto exit; - return_value = builtin_pow_impl(module, x, y, z); - -exit: - return return_value; -} - static PyObject * builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z) -/*[clinic end generated code: output=d0cdf314311dedba input=561a942d5f5c1899]*/ +/*[clinic end generated code: output=1fba268adba9b45f input=561a942d5f5c1899]*/ { return PyNumber_Power(x, y, z); } @@ -2304,43 +1795,9 @@ If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_input__doc__, -"input($module, prompt=None, /)\n" -"--\n" -"\n" -"Read a string from standard input. The trailing newline is stripped.\n" -"\n" -"The prompt string, if given, is printed to standard output without a\n" -"trailing newline before reading input.\n" -"\n" -"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n" -"On *nix systems, readline is used if available."); - -#define BUILTIN_INPUT_METHODDEF \ - {"input", (PyCFunction)builtin_input, METH_VARARGS, builtin_input__doc__}, - -static PyObject * -builtin_input_impl(PyModuleDef *module, PyObject *prompt); - -static PyObject * -builtin_input(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *prompt = NULL; - - if (!PyArg_UnpackTuple(args, "input", - 0, 1, - &prompt)) - goto exit; - return_value = builtin_input_impl(module, prompt); - -exit: - return return_value; -} - static PyObject * builtin_input_impl(PyModuleDef *module, PyObject *prompt) -/*[clinic end generated code: output=69323bf5695f7c9c input=5e8bb70c2908fe3c]*/ +/*[clinic end generated code: output=b77731f59e1515c4 input=5e8bb70c2908fe3c]*/ { PyObject *fin = _PySys_GetObjectId(&PyId_stdin); PyObject *fout = _PySys_GetObjectId(&PyId_stdout); @@ -2523,20 +1980,9 @@ Return the canonical string representation of the object. For many object types, including most builtins, eval(repr(obj)) == obj. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_repr__doc__, -"repr($module, obj, /)\n" -"--\n" -"\n" -"Return the canonical string representation of the object.\n" -"\n" -"For many object types, including most builtins, eval(repr(obj)) == obj."); - -#define BUILTIN_REPR_METHODDEF \ - {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__}, - static PyObject * builtin_repr(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=988980120f39e2fa input=a2bca0f38a5a924d]*/ +/*[clinic end generated code: output=dc41784fa4341834 input=a2bca0f38a5a924d]*/ { return PyObject_Repr(obj); } @@ -2704,42 +2150,9 @@ This function is intended specifically for use with numeric values and may reject non-numeric types. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_sum__doc__, -"sum($module, iterable, start=0, /)\n" -"--\n" -"\n" -"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n" -"\n" -"When the iterable is empty, return the start value.\n" -"This function is intended specifically for use with numeric values and may\n" -"reject non-numeric types."); - -#define BUILTIN_SUM_METHODDEF \ - {"sum", (PyCFunction)builtin_sum, METH_VARARGS, builtin_sum__doc__}, - -static PyObject * -builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start); - -static PyObject * -builtin_sum(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *iterable; - PyObject *start = NULL; - - if (!PyArg_UnpackTuple(args, "sum", - 1, 2, - &iterable, &start)) - goto exit; - return_value = builtin_sum_impl(module, iterable, start); - -exit: - return return_value; -} - static PyObject * builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start) -/*[clinic end generated code: output=b42652a0d5f64f6b input=90ae7a242cfcf025]*/ +/*[clinic end generated code: output=33655b248b21d581 input=90ae7a242cfcf025]*/ { PyObject *result = start; PyObject *temp, *item, *iter; @@ -2914,42 +2327,9 @@ check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B) or ...`` etc. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_isinstance__doc__, -"isinstance($module, obj, class_or_tuple, /)\n" -"--\n" -"\n" -"Return whether an object is an instance of a class or of a subclass thereof.\n" -"\n" -"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n" -"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n" -"or ...`` etc."); - -#define BUILTIN_ISINSTANCE_METHODDEF \ - {"isinstance", (PyCFunction)builtin_isinstance, METH_VARARGS, builtin_isinstance__doc__}, - -static PyObject * -builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, PyObject *class_or_tuple); - -static PyObject * -builtin_isinstance(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *obj; - PyObject *class_or_tuple; - - if (!PyArg_UnpackTuple(args, "isinstance", - 2, 2, - &obj, &class_or_tuple)) - goto exit; - return_value = builtin_isinstance_impl(module, obj, class_or_tuple); - -exit: - return return_value; -} - static PyObject * builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, PyObject *class_or_tuple) -/*[clinic end generated code: output=847df57fef8ddea7 input=cf9eb0ad6bb9bad6]*/ +/*[clinic end generated code: output=5e234dc3872d75a2 input=cf9eb0ad6bb9bad6]*/ { int retval; @@ -2974,42 +2354,9 @@ check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B) or ...`` etc. [clinic start generated code]*/ -PyDoc_STRVAR(builtin_issubclass__doc__, -"issubclass($module, cls, class_or_tuple, /)\n" -"--\n" -"\n" -"Return whether \'cls\' is a derived from another class or is the same class.\n" -"\n" -"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n" -"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n" -"or ...`` etc."); - -#define BUILTIN_ISSUBCLASS_METHODDEF \ - {"issubclass", (PyCFunction)builtin_issubclass, METH_VARARGS, builtin_issubclass__doc__}, - -static PyObject * -builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, PyObject *class_or_tuple); - -static PyObject * -builtin_issubclass(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *cls; - PyObject *class_or_tuple; - - if (!PyArg_UnpackTuple(args, "issubclass", - 2, 2, - &cls, &class_or_tuple)) - goto exit; - return_value = builtin_issubclass_impl(module, cls, class_or_tuple); - -exit: - return return_value; -} - static PyObject * builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, PyObject *class_or_tuple) -/*[clinic end generated code: output=a0f8c03692e35474 input=923d03fa41fc352a]*/ +/*[clinic end generated code: output=6346a85ba15dbd7d input=923d03fa41fc352a]*/ { int retval; -- cgit v1.2.1 From 8f7e37ea29d7bdfadb98c3ef264862962e99748c Mon Sep 17 00:00:00 2001 From: Larry Hastings Date: Tue, 14 Apr 2015 18:07:59 -0400 Subject: Issue #23944: Argument Clinic now wraps long impl prototypes at column 78. --- Python/bltinmodule.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index e733485111..e6d2bab1b3 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -574,8 +574,9 @@ format_spec defaults to the empty string [clinic start generated code]*/ static PyObject * -builtin_format_impl(PyModuleDef *module, PyObject *value, PyObject *format_spec) -/*[clinic end generated code: output=fae3e927cc715466 input=e23f2f11e0098c64]*/ +builtin_format_impl(PyModuleDef *module, PyObject *value, + PyObject *format_spec) +/*[clinic end generated code: output=4341fd78a5f01764 input=e23f2f11e0098c64]*/ { return PyObject_Format(value, format_spec); } @@ -654,8 +655,10 @@ in addition to any features explicitly specified. [clinic start generated code]*/ static PyObject * -builtin_compile_impl(PyModuleDef *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, int optimize) -/*[clinic end generated code: output=4f41a315386bab9f input=c6212a9d21472f7e]*/ +builtin_compile_impl(PyModuleDef *module, PyObject *source, + PyObject *filename, const char *mode, int flags, + int dont_inherit, int optimize) +/*[clinic end generated code: output=31881762c1bb90c4 input=c6212a9d21472f7e]*/ { Py_buffer view = {NULL, NULL}; const char *str; @@ -805,8 +808,9 @@ If only globals is given, locals defaults to it. [clinic start generated code]*/ static PyObject * -builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals) -/*[clinic end generated code: output=90642b79dd8b08d6 input=31e42c1d2125b50b]*/ +builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, + PyObject *locals) +/*[clinic end generated code: output=7284501fb7b4d666 input=31e42c1d2125b50b]*/ { PyObject *result, *tmp = NULL; Py_buffer view = {NULL, NULL}; @@ -889,8 +893,9 @@ If only globals is given, locals defaults to it. [clinic start generated code]*/ static PyObject * -builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals) -/*[clinic end generated code: output=e8e0bbcde826a048 input=536e057b5e00d89e]*/ +builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, + PyObject *locals) +/*[clinic end generated code: output=83d574ef9d5d0b46 input=536e057b5e00d89e]*/ { PyObject *v; @@ -1303,8 +1308,9 @@ setattr(x, 'y', v) is equivalent to ``x.y = v'' [clinic start generated code]*/ static PyObject * -builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, PyObject *value) -/*[clinic end generated code: output=c5e0a3a3971333ed input=fbe7e53403116b93]*/ +builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, + PyObject *value) +/*[clinic end generated code: output=d881c655c0f7e34f input=fbe7e53403116b93]*/ { if (PyObject_SetAttr(obj, name, value) != 0) return NULL; @@ -2328,8 +2334,9 @@ or ...`` etc. [clinic start generated code]*/ static PyObject * -builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, PyObject *class_or_tuple) -/*[clinic end generated code: output=5e234dc3872d75a2 input=cf9eb0ad6bb9bad6]*/ +builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, + PyObject *class_or_tuple) +/*[clinic end generated code: output=f960b7c12dbbeda0 input=cf9eb0ad6bb9bad6]*/ { int retval; @@ -2355,8 +2362,9 @@ or ...`` etc. [clinic start generated code]*/ static PyObject * -builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, PyObject *class_or_tuple) -/*[clinic end generated code: output=6346a85ba15dbd7d input=923d03fa41fc352a]*/ +builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, + PyObject *class_or_tuple) +/*[clinic end generated code: output=8b012a151940bbf2 input=923d03fa41fc352a]*/ { int retval; -- cgit v1.2.1 From d7ec94fe5c3ac4463377ac6e5957917fdb19ae93 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 30 May 2015 11:09:35 +0300 Subject: Use converter names instead of format units in Argument Clinic descriptions in builtin and _crypt modules. --- Python/bltinmodule.c | 144 +++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index e6d2bab1b3..b05a70f1dd 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -235,7 +235,7 @@ is the number of parent directories to search relative to the current module."); /*[clinic input] abs as builtin_abs - x: 'O' + x: object / Return the absolute value of the argument. @@ -243,7 +243,7 @@ Return the absolute value of the argument. static PyObject * builtin_abs(PyModuleDef *module, PyObject *x) -/*[clinic end generated code: output=6833047c493ecea2 input=aa29cc07869b4732]*/ +/*[clinic end generated code: output=6833047c493ecea2 input=bed4ca14e29c20d1]*/ { return PyNumber_Absolute(x); } @@ -251,7 +251,7 @@ builtin_abs(PyModuleDef *module, PyObject *x) /*[clinic input] all as builtin_all - iterable: 'O' + iterable: object / Return True if bool(x) is True for all values x in the iterable. @@ -261,7 +261,7 @@ If the iterable is empty, return True. static PyObject * builtin_all(PyModuleDef *module, PyObject *iterable) -/*[clinic end generated code: output=089e6d1b7bde27b1 input=dd506dc9998d42bd]*/ +/*[clinic end generated code: output=089e6d1b7bde27b1 input=1a7c5d1bc3438a21]*/ { PyObject *it, *item; PyObject *(*iternext)(PyObject *); @@ -300,7 +300,7 @@ builtin_all(PyModuleDef *module, PyObject *iterable) /*[clinic input] any as builtin_any - iterable: 'O' + iterable: object / Return True if bool(x) is True for any x in the iterable. @@ -310,7 +310,7 @@ If the iterable is empty, return False. static PyObject * builtin_any(PyModuleDef *module, PyObject *iterable) -/*[clinic end generated code: output=1be994b2c2307492 input=8fe8460f3fbbced8]*/ +/*[clinic end generated code: output=1be994b2c2307492 input=41d7451c23384f24]*/ { PyObject *it, *item; PyObject *(*iternext)(PyObject *); @@ -349,7 +349,7 @@ builtin_any(PyModuleDef *module, PyObject *iterable) /*[clinic input] ascii as builtin_ascii - obj: 'O' + obj: object / Return an ASCII-only representation of an object. @@ -362,7 +362,7 @@ to that returned by repr() in Python 2. static PyObject * builtin_ascii(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=d4e862c48af2a933 input=0cbdc1420a306325]*/ +/*[clinic end generated code: output=d4e862c48af2a933 input=4c62732e1b3a3cc9]*/ { return PyObject_ASCII(obj); } @@ -371,7 +371,7 @@ builtin_ascii(PyModuleDef *module, PyObject *obj) /*[clinic input] bin as builtin_bin - number: 'O' + number: object / Return the binary representation of an integer. @@ -382,7 +382,7 @@ Return the binary representation of an integer. static PyObject * builtin_bin(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=25ee26c6cf3bbb54 input=2a6362ae9a9c9203]*/ +/*[clinic end generated code: output=25ee26c6cf3bbb54 input=53f8a0264bacaf90]*/ { return PyNumber_ToBase(number, 2); } @@ -391,7 +391,7 @@ builtin_bin(PyModuleDef *module, PyObject *number) /*[clinic input] callable as builtin_callable - obj: 'O' + obj: object / Return whether the object is callable (i.e., some kind of function). @@ -402,7 +402,7 @@ __call__() method. static PyObject * builtin_callable(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=f4df2ce92364b656 input=bb3bb528fffdade4]*/ +/*[clinic end generated code: output=f4df2ce92364b656 input=1423bab99cc41f58]*/ { return PyBool_FromLong((long)PyCallable_Check(obj)); } @@ -564,7 +564,7 @@ PyTypeObject PyFilter_Type = { /*[clinic input] format as builtin_format - value: 'O' + value: object format_spec: unicode(c_default="NULL") = '' / @@ -576,7 +576,7 @@ format_spec defaults to the empty string static PyObject * builtin_format_impl(PyModuleDef *module, PyObject *value, PyObject *format_spec) -/*[clinic end generated code: output=4341fd78a5f01764 input=e23f2f11e0098c64]*/ +/*[clinic end generated code: output=4341fd78a5f01764 input=6325e751a1b29b86]*/ { return PyObject_Format(value, format_spec); } @@ -584,7 +584,7 @@ builtin_format_impl(PyModuleDef *module, PyObject *value, /*[clinic input] chr as builtin_chr - i: 'i' + i: int / Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff. @@ -592,7 +592,7 @@ Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff. static PyObject * builtin_chr_impl(PyModuleDef *module, int i) -/*[clinic end generated code: output=67fe4d87e690f373 input=9b1ced29615adf66]*/ +/*[clinic end generated code: output=67fe4d87e690f373 input=3f604ef45a70750d]*/ { return PyUnicode_FromOrdinal(i); } @@ -633,12 +633,12 @@ source_as_string(PyObject *cmd, const char *funcname, const char *what, PyCompil /*[clinic input] compile as builtin_compile - source: 'O' + source: object filename: object(converter="PyUnicode_FSDecoder") - mode: 's' - flags: 'i' = 0 - dont_inherit: 'i' = 0 - optimize: 'i' = -1 + mode: str + flags: int = 0 + dont_inherit: int = 0 + optimize: int = -1 Compile source into a code object that can be executed by exec() or eval(). @@ -658,7 +658,7 @@ static PyObject * builtin_compile_impl(PyModuleDef *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, int optimize) -/*[clinic end generated code: output=31881762c1bb90c4 input=c6212a9d21472f7e]*/ +/*[clinic end generated code: output=31881762c1bb90c4 input=7faa105f669fefcf]*/ { Py_buffer view = {NULL, NULL}; const char *str; @@ -775,8 +775,8 @@ PyDoc_STRVAR(dir_doc, /*[clinic input] divmod as builtin_divmod - x: 'O' - y: 'O' + x: object + y: object / Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. @@ -784,7 +784,7 @@ Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. static PyObject * builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y) -/*[clinic end generated code: output=9ad0076120ebf9ac input=c9c617b7bb74c615]*/ +/*[clinic end generated code: output=9ad0076120ebf9ac input=7fdb15f8a97a5fe7]*/ { return PyNumber_Divmod(x, y); } @@ -793,9 +793,9 @@ builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y) /*[clinic input] eval as builtin_eval - source: 'O' - globals: 'O' = None - locals: 'O' = None + source: object + globals: object = None + locals: object = None / Evaluate the given source in the context of globals and locals. @@ -810,7 +810,7 @@ If only globals is given, locals defaults to it. static PyObject * builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals) -/*[clinic end generated code: output=7284501fb7b4d666 input=31e42c1d2125b50b]*/ +/*[clinic end generated code: output=7284501fb7b4d666 input=11ee718a8640e527]*/ { PyObject *result, *tmp = NULL; Py_buffer view = {NULL, NULL}; @@ -878,9 +878,9 @@ builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, /*[clinic input] exec as builtin_exec - source: 'O' - globals: 'O' = None - locals: 'O' = None + source: object + globals: object = None + locals: object = None / Execute the given source in the context of globals and locals. @@ -895,7 +895,7 @@ If only globals is given, locals defaults to it. static PyObject * builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals) -/*[clinic end generated code: output=83d574ef9d5d0b46 input=536e057b5e00d89e]*/ +/*[clinic end generated code: output=83d574ef9d5d0b46 input=01ca3e1c01692829]*/ { PyObject *v; @@ -1022,8 +1022,8 @@ builtin_globals_impl(PyModuleDef *module) /*[clinic input] hasattr as builtin_hasattr - obj: 'O' - name: 'O' + obj: object + name: object / Return whether the object has an attribute with the given name. @@ -1033,7 +1033,7 @@ This is done by calling getattr(obj, name) and catching AttributeError. static PyObject * builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) -/*[clinic end generated code: output=81154fdd63634696 input=b50bad5f739ea10d]*/ +/*[clinic end generated code: output=81154fdd63634696 input=0faec9787d979542]*/ { PyObject *v; @@ -1063,7 +1063,7 @@ builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) id as builtin_id self: self(type="PyModuleDef *") - obj as v: 'O' + obj as v: object / Return the identity of an object. @@ -1074,7 +1074,7 @@ This is guaranteed to be unique among simultaneously existing objects. static PyObject * builtin_id(PyModuleDef *self, PyObject *v) -/*[clinic end generated code: output=0aa640785f697f65 input=a1f988d98357341d]*/ +/*[clinic end generated code: output=0aa640785f697f65 input=5a534136419631f4]*/ { return PyLong_FromVoidPtr(v); } @@ -1297,9 +1297,9 @@ is exhausted, it is returned instead of raising StopIteration."); /*[clinic input] setattr as builtin_setattr - obj: 'O' - name: 'O' - value: 'O' + obj: object + name: object + value: object / Sets the named attribute on the given object to the specified value. @@ -1310,7 +1310,7 @@ setattr(x, 'y', v) is equivalent to ``x.y = v'' static PyObject * builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, PyObject *value) -/*[clinic end generated code: output=d881c655c0f7e34f input=fbe7e53403116b93]*/ +/*[clinic end generated code: output=d881c655c0f7e34f input=bd2b7ca6875a1899]*/ { if (PyObject_SetAttr(obj, name, value) != 0) return NULL; @@ -1322,8 +1322,8 @@ builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, /*[clinic input] delattr as builtin_delattr - obj: 'O' - name: 'O' + obj: object + name: object / Deletes the named attribute from the given object. @@ -1333,7 +1333,7 @@ delattr(x, 'y') is equivalent to ``del x.y'' static PyObject * builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) -/*[clinic end generated code: output=ef653e698a0b4187 input=647af2ce9183a823]*/ +/*[clinic end generated code: output=ef653e698a0b4187 input=db16685d6b4b9410]*/ { if (PyObject_SetAttr(obj, name, (PyObject *)NULL) != 0) return NULL; @@ -1345,7 +1345,7 @@ builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) /*[clinic input] hash as builtin_hash - obj: 'O' + obj: object / Return the hash value for the given object. @@ -1356,7 +1356,7 @@ reverse is not necessarily true. static PyObject * builtin_hash(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=1f32ff154c1f751a input=ccc4d2b9a351df4e]*/ +/*[clinic end generated code: output=1f32ff154c1f751a input=58c48be822bf9c54]*/ { Py_hash_t x; @@ -1370,7 +1370,7 @@ builtin_hash(PyModuleDef *module, PyObject *obj) /*[clinic input] hex as builtin_hex - number: 'O' + number: object / Return the hexadecimal representation of an integer. @@ -1381,7 +1381,7 @@ Return the hexadecimal representation of an integer. static PyObject * builtin_hex(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=618489ce3cbc5858 input=e816200b0a728ebe]*/ +/*[clinic end generated code: output=618489ce3cbc5858 input=e645aff5fc7d540e]*/ { return PyNumber_ToBase(number, 16); } @@ -1417,7 +1417,7 @@ In the second form, the callable is called until it returns the sentinel."); /*[clinic input] len as builtin_len - obj: 'O' + obj: object / Return the number of items in a container. @@ -1425,7 +1425,7 @@ Return the number of items in a container. static PyObject * builtin_len(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=8e5837b6f81d915b input=2e5ff15db9a2de22]*/ +/*[clinic end generated code: output=8e5837b6f81d915b input=bc55598da9e9c9b5]*/ { Py_ssize_t res; @@ -1596,7 +1596,7 @@ With two or more arguments, return the largest argument."); /*[clinic input] oct as builtin_oct - number: 'O' + number: object / Return the octal representation of an integer. @@ -1607,7 +1607,7 @@ Return the octal representation of an integer. static PyObject * builtin_oct(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=18f701bc6d8f804a input=a3a372b521b3dd13]*/ +/*[clinic end generated code: output=18f701bc6d8f804a input=ad6b274af4016c72]*/ { return PyNumber_ToBase(number, 8); } @@ -1616,7 +1616,7 @@ builtin_oct(PyModuleDef *module, PyObject *number) /*[clinic input] ord as builtin_ord - c: 'O' + c: object / Return the Unicode code point for a one-character string. @@ -1624,7 +1624,7 @@ Return the Unicode code point for a one-character string. static PyObject * builtin_ord(PyModuleDef *module, PyObject *c) -/*[clinic end generated code: output=04fd27272d9462f6 input=762355f87451efa3]*/ +/*[clinic end generated code: output=04fd27272d9462f6 input=3064e5d6203ad012]*/ { long ord; Py_ssize_t size; @@ -1671,9 +1671,9 @@ builtin_ord(PyModuleDef *module, PyObject *c) /*[clinic input] pow as builtin_pow - x: 'O' - y: 'O' - z: 'O' = None + x: object + y: object + z: object = None / Equivalent to x**y (with two arguments) or x**y % z (with three arguments) @@ -1684,7 +1684,7 @@ invoked using the three argument form. static PyObject * builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z) -/*[clinic end generated code: output=1fba268adba9b45f input=561a942d5f5c1899]*/ +/*[clinic end generated code: output=1fba268adba9b45f input=653d57d38d41fc07]*/ { return PyNumber_Power(x, y, z); } @@ -1978,7 +1978,7 @@ builtin_input_impl(PyModuleDef *module, PyObject *prompt) /*[clinic input] repr as builtin_repr - obj: 'O' + obj: object / Return the canonical string representation of the object. @@ -1988,7 +1988,7 @@ For many object types, including most builtins, eval(repr(obj)) == obj. static PyObject * builtin_repr(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=dc41784fa4341834 input=a2bca0f38a5a924d]*/ +/*[clinic end generated code: output=dc41784fa4341834 input=1c9e6d66d3e3be04]*/ { return PyObject_Repr(obj); } @@ -2045,9 +2045,9 @@ same type as the number. ndigits may be negative."); /* [disabled clinic input] sorted as builtin_sorted - iterable as seq: 'O' - key as keyfunc: 'O' = None - reverse: 'O' = False + iterable as seq: object + key as keyfunc: object = None + reverse: object = False Return a new list containing all items from the iterable in ascending order. @@ -2145,7 +2145,7 @@ With an argument, equivalent to object.__dict__."); /*[clinic input] sum as builtin_sum - iterable: 'O' + iterable: object start: object(c_default="NULL") = 0 / @@ -2158,7 +2158,7 @@ reject non-numeric types. static PyObject * builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start) -/*[clinic end generated code: output=33655b248b21d581 input=90ae7a242cfcf025]*/ +/*[clinic end generated code: output=33655b248b21d581 input=3b5b7a9d7611c73a]*/ { PyObject *result = start; PyObject *temp, *item, *iter; @@ -2322,8 +2322,8 @@ builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start) /*[clinic input] isinstance as builtin_isinstance - obj: 'O' - class_or_tuple: 'O' + obj: object + class_or_tuple: object / Return whether an object is an instance of a class or of a subclass thereof. @@ -2336,7 +2336,7 @@ or ...`` etc. static PyObject * builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, PyObject *class_or_tuple) -/*[clinic end generated code: output=f960b7c12dbbeda0 input=cf9eb0ad6bb9bad6]*/ +/*[clinic end generated code: output=f960b7c12dbbeda0 input=ffa743db1daf7549]*/ { int retval; @@ -2350,8 +2350,8 @@ builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, /*[clinic input] issubclass as builtin_issubclass - cls: 'O' - class_or_tuple: 'O' + cls: object + class_or_tuple: object / Return whether 'cls' is a derived from another class or is the same class. @@ -2364,7 +2364,7 @@ or ...`` etc. static PyObject * builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, PyObject *class_or_tuple) -/*[clinic end generated code: output=8b012a151940bbf2 input=923d03fa41fc352a]*/ +/*[clinic end generated code: output=8b012a151940bbf2 input=af5f35e9ceaddaf6]*/ { int retval; -- cgit v1.2.1 From 4a7c3504f8559e7981b06092328d00e03bdad187 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 30 May 2015 11:30:39 +0300 Subject: Specify default values of semantic booleans in Argument Clinic generated signatures as booleans. --- Python/bltinmodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index b05a70f1dd..2f22209e9d 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -637,7 +637,7 @@ compile as builtin_compile filename: object(converter="PyUnicode_FSDecoder") mode: str flags: int = 0 - dont_inherit: int = 0 + dont_inherit: int(c_default="0") = False optimize: int = -1 Compile source into a code object that can be executed by exec() or eval(). @@ -648,9 +648,9 @@ The mode must be 'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression. The flags argument, if present, controls which future statements influence the compilation of the code. -The dont_inherit argument, if non-zero, stops the compilation inheriting +The dont_inherit argument, if true, stops the compilation inheriting the effects of any future statements in effect in the code calling -compile; if absent or zero these statements do influence the compilation, +compile; if absent or false these statements do influence the compilation, in addition to any features explicitly specified. [clinic start generated code]*/ @@ -658,7 +658,7 @@ static PyObject * builtin_compile_impl(PyModuleDef *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, int optimize) -/*[clinic end generated code: output=31881762c1bb90c4 input=7faa105f669fefcf]*/ +/*[clinic end generated code: output=31881762c1bb90c4 input=9d53e8cfb3c86414]*/ { Py_buffer view = {NULL, NULL}; const char *str; -- cgit v1.2.1 From 3530325be1eda3ed18cb069980a7d6fe8d583650 Mon Sep 17 00:00:00 2001 From: Zachary Ware Date: Thu, 28 Apr 2016 14:24:55 -0500 Subject: Issue #26874: Fix divmod docstring --- Python/bltinmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index a06ef610c6..909c5b904f 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -796,7 +796,7 @@ divmod as builtin_divmod y: object / -Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. +Return the tuple ((x-x%y)//y, x%y). Invariant: div*y + mod == x. [clinic start generated code]*/ static PyObject * -- cgit v1.2.1 From ce3b9e2c673b9806d2ed421fd77ff560b3990ad8 Mon Sep 17 00:00:00 2001 From: Zachary Ware Date: Thu, 28 Apr 2016 14:39:50 -0500 Subject: Issue #26874: Simplify the divmod docstring --- Python/bltinmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 909c5b904f..0065c9e009 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -796,7 +796,7 @@ divmod as builtin_divmod y: object / -Return the tuple ((x-x%y)//y, x%y). Invariant: div*y + mod == x. +Return the tuple (x//y, x%y). Invariant: div*y + mod == x. [clinic start generated code]*/ static PyObject * -- cgit v1.2.1 From 9d801b83fe62155003b33fca36c4c7278ad465da Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 1 May 2016 20:33:24 +0300 Subject: Regenerate Argument Clinic code for issue #26874. --- Python/bltinmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 0065c9e009..f3d0c9a870 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -801,7 +801,7 @@ Return the tuple (x//y, x%y). Invariant: div*y + mod == x. static PyObject * builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y) -/*[clinic end generated code: output=9ad0076120ebf9ac input=7fdb15f8a97a5fe7]*/ +/*[clinic end generated code: output=9ad0076120ebf9ac input=175ad9c84ff41a85]*/ { return PyNumber_Divmod(x, y); } -- cgit v1.2.1 From ee021560b19d20eeea7c66c30003973f21381cdb Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 7 Jul 2016 17:35:15 +0300 Subject: Issue #27332: Fixed the type of the first argument of module-level functions generated by Argument Clinic. Patch by Petr Viktorin. --- Python/bltinmodule.c | 117 +++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 59 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index f3d0c9a870..eedd7c3c3c 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -242,8 +242,8 @@ Return the absolute value of the argument. [clinic start generated code]*/ static PyObject * -builtin_abs(PyModuleDef *module, PyObject *x) -/*[clinic end generated code: output=6833047c493ecea2 input=bed4ca14e29c20d1]*/ +builtin_abs(PyObject *module, PyObject *x) +/*[clinic end generated code: output=b1b433b9e51356f5 input=bed4ca14e29c20d1]*/ { return PyNumber_Absolute(x); } @@ -260,8 +260,8 @@ If the iterable is empty, return True. [clinic start generated code]*/ static PyObject * -builtin_all(PyModuleDef *module, PyObject *iterable) -/*[clinic end generated code: output=089e6d1b7bde27b1 input=1a7c5d1bc3438a21]*/ +builtin_all(PyObject *module, PyObject *iterable) +/*[clinic end generated code: output=ca2a7127276f79b3 input=1a7c5d1bc3438a21]*/ { PyObject *it, *item; PyObject *(*iternext)(PyObject *); @@ -309,8 +309,8 @@ If the iterable is empty, return False. [clinic start generated code]*/ static PyObject * -builtin_any(PyModuleDef *module, PyObject *iterable) -/*[clinic end generated code: output=1be994b2c2307492 input=41d7451c23384f24]*/ +builtin_any(PyObject *module, PyObject *iterable) +/*[clinic end generated code: output=fa65684748caa60e input=41d7451c23384f24]*/ { PyObject *it, *item; PyObject *(*iternext)(PyObject *); @@ -361,8 +361,8 @@ to that returned by repr() in Python 2. [clinic start generated code]*/ static PyObject * -builtin_ascii(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=d4e862c48af2a933 input=4c62732e1b3a3cc9]*/ +builtin_ascii(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=6d37b3f0984c7eb9 input=4c62732e1b3a3cc9]*/ { return PyObject_ASCII(obj); } @@ -381,8 +381,8 @@ Return the binary representation of an integer. [clinic start generated code]*/ static PyObject * -builtin_bin(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=25ee26c6cf3bbb54 input=53f8a0264bacaf90]*/ +builtin_bin(PyObject *module, PyObject *number) +/*[clinic end generated code: output=b6fc4ad5e649f4f7 input=53f8a0264bacaf90]*/ { return PyNumber_ToBase(number, 2); } @@ -401,8 +401,8 @@ __call__() method. [clinic start generated code]*/ static PyObject * -builtin_callable(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=f4df2ce92364b656 input=1423bab99cc41f58]*/ +builtin_callable(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=2b095d59d934cb7e input=1423bab99cc41f58]*/ { return PyBool_FromLong((long)PyCallable_Check(obj)); } @@ -574,9 +574,8 @@ format_spec defaults to the empty string [clinic start generated code]*/ static PyObject * -builtin_format_impl(PyModuleDef *module, PyObject *value, - PyObject *format_spec) -/*[clinic end generated code: output=4341fd78a5f01764 input=6325e751a1b29b86]*/ +builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec) +/*[clinic end generated code: output=2f40bdfa4954b077 input=6325e751a1b29b86]*/ { return PyObject_Format(value, format_spec); } @@ -591,8 +590,8 @@ Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff. [clinic start generated code]*/ static PyObject * -builtin_chr_impl(PyModuleDef *module, int i) -/*[clinic end generated code: output=67fe4d87e690f373 input=3f604ef45a70750d]*/ +builtin_chr_impl(PyObject *module, int i) +/*[clinic end generated code: output=c733afcd200afcb7 input=3f604ef45a70750d]*/ { return PyUnicode_FromOrdinal(i); } @@ -672,10 +671,10 @@ in addition to any features explicitly specified. [clinic start generated code]*/ static PyObject * -builtin_compile_impl(PyModuleDef *module, PyObject *source, - PyObject *filename, const char *mode, int flags, - int dont_inherit, int optimize) -/*[clinic end generated code: output=31881762c1bb90c4 input=9d53e8cfb3c86414]*/ +builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, + const char *mode, int flags, int dont_inherit, + int optimize) +/*[clinic end generated code: output=1fa176e33452bb63 input=9d53e8cfb3c86414]*/ { PyObject *source_copy; const char *str; @@ -800,8 +799,8 @@ Return the tuple (x//y, x%y). Invariant: div*y + mod == x. [clinic start generated code]*/ static PyObject * -builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y) -/*[clinic end generated code: output=9ad0076120ebf9ac input=175ad9c84ff41a85]*/ +builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y) +/*[clinic end generated code: output=b06d8a5f6e0c745e input=175ad9c84ff41a85]*/ { return PyNumber_Divmod(x, y); } @@ -825,9 +824,9 @@ If only globals is given, locals defaults to it. [clinic start generated code]*/ static PyObject * -builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, +builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, PyObject *locals) -/*[clinic end generated code: output=7284501fb7b4d666 input=11ee718a8640e527]*/ +/*[clinic end generated code: output=0a0824aa70093116 input=11ee718a8640e527]*/ { PyObject *result, *source_copy; const char *str; @@ -908,9 +907,9 @@ If only globals is given, locals defaults to it. [clinic start generated code]*/ static PyObject * -builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, +builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, PyObject *locals) -/*[clinic end generated code: output=83d574ef9d5d0b46 input=01ca3e1c01692829]*/ +/*[clinic end generated code: output=3c90efc6ab68ef5d input=01ca3e1c01692829]*/ { PyObject *v; @@ -1024,8 +1023,8 @@ global scope and vice-versa. [clinic start generated code]*/ static PyObject * -builtin_globals_impl(PyModuleDef *module) -/*[clinic end generated code: output=4958645e96dd8138 input=9327576f92bb48ba]*/ +builtin_globals_impl(PyObject *module) +/*[clinic end generated code: output=e5dd1527067b94d2 input=9327576f92bb48ba]*/ { PyObject *d; @@ -1048,8 +1047,8 @@ This is done by calling getattr(obj, name) and catching AttributeError. [clinic start generated code]*/ static PyObject * -builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) -/*[clinic end generated code: output=81154fdd63634696 input=0faec9787d979542]*/ +builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name) +/*[clinic end generated code: output=a7aff2090a4151e5 input=0faec9787d979542]*/ { PyObject *v; @@ -1324,9 +1323,9 @@ setattr(x, 'y', v) is equivalent to ``x.y = v'' [clinic start generated code]*/ static PyObject * -builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, +builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name, PyObject *value) -/*[clinic end generated code: output=d881c655c0f7e34f input=bd2b7ca6875a1899]*/ +/*[clinic end generated code: output=dc2ce1d1add9acb4 input=bd2b7ca6875a1899]*/ { if (PyObject_SetAttr(obj, name, value) != 0) return NULL; @@ -1348,8 +1347,8 @@ delattr(x, 'y') is equivalent to ``del x.y'' [clinic start generated code]*/ static PyObject * -builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name) -/*[clinic end generated code: output=ef653e698a0b4187 input=db16685d6b4b9410]*/ +builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name) +/*[clinic end generated code: output=85134bc58dff79fa input=db16685d6b4b9410]*/ { if (PyObject_SetAttr(obj, name, (PyObject *)NULL) != 0) return NULL; @@ -1371,8 +1370,8 @@ reverse is not necessarily true. [clinic start generated code]*/ static PyObject * -builtin_hash(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=1f32ff154c1f751a input=58c48be822bf9c54]*/ +builtin_hash(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=237668e9d7688db7 input=58c48be822bf9c54]*/ { Py_hash_t x; @@ -1396,8 +1395,8 @@ Return the hexadecimal representation of an integer. [clinic start generated code]*/ static PyObject * -builtin_hex(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=618489ce3cbc5858 input=e645aff5fc7d540e]*/ +builtin_hex(PyObject *module, PyObject *number) +/*[clinic end generated code: output=e46b612169099408 input=e645aff5fc7d540e]*/ { return PyNumber_ToBase(number, 16); } @@ -1440,8 +1439,8 @@ Return the number of items in a container. [clinic start generated code]*/ static PyObject * -builtin_len(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=8e5837b6f81d915b input=bc55598da9e9c9b5]*/ +builtin_len(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=fa7a270d314dfb6c input=bc55598da9e9c9b5]*/ { Py_ssize_t res; @@ -1463,8 +1462,8 @@ covered by any backwards compatibility guarantees. [clinic start generated code]*/ static PyObject * -builtin_locals_impl(PyModuleDef *module) -/*[clinic end generated code: output=8b5a41f12e19d13a input=7874018d478d5c4b]*/ +builtin_locals_impl(PyObject *module) +/*[clinic end generated code: output=b46c94015ce11448 input=7874018d478d5c4b]*/ { PyObject *d; @@ -1622,8 +1621,8 @@ Return the octal representation of an integer. [clinic start generated code]*/ static PyObject * -builtin_oct(PyModuleDef *module, PyObject *number) -/*[clinic end generated code: output=18f701bc6d8f804a input=ad6b274af4016c72]*/ +builtin_oct(PyObject *module, PyObject *number) +/*[clinic end generated code: output=40a34656b6875352 input=ad6b274af4016c72]*/ { return PyNumber_ToBase(number, 8); } @@ -1639,8 +1638,8 @@ Return the Unicode code point for a one-character string. [clinic start generated code]*/ static PyObject * -builtin_ord(PyModuleDef *module, PyObject *c) -/*[clinic end generated code: output=04fd27272d9462f6 input=3064e5d6203ad012]*/ +builtin_ord(PyObject *module, PyObject *c) +/*[clinic end generated code: output=4fa5e87a323bae71 input=3064e5d6203ad012]*/ { long ord; Py_ssize_t size; @@ -1699,8 +1698,8 @@ invoked using the three argument form. [clinic start generated code]*/ static PyObject * -builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z) -/*[clinic end generated code: output=1fba268adba9b45f input=653d57d38d41fc07]*/ +builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z) +/*[clinic end generated code: output=50a14d5d130d404b input=653d57d38d41fc07]*/ { return PyNumber_Power(x, y, z); } @@ -1818,8 +1817,8 @@ On *nix systems, readline is used if available. [clinic start generated code]*/ static PyObject * -builtin_input_impl(PyModuleDef *module, PyObject *prompt) -/*[clinic end generated code: output=b77731f59e1515c4 input=5e8bb70c2908fe3c]*/ +builtin_input_impl(PyObject *module, PyObject *prompt) +/*[clinic end generated code: output=83db5a191e7a0d60 input=5e8bb70c2908fe3c]*/ { PyObject *fin = _PySys_GetObjectId(&PyId_stdin); PyObject *fout = _PySys_GetObjectId(&PyId_stdout); @@ -2005,8 +2004,8 @@ For many object types, including most builtins, eval(repr(obj)) == obj. [clinic start generated code]*/ static PyObject * -builtin_repr(PyModuleDef *module, PyObject *obj) -/*[clinic end generated code: output=dc41784fa4341834 input=1c9e6d66d3e3be04]*/ +builtin_repr(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=7ed3778c44fd0194 input=1c9e6d66d3e3be04]*/ { return PyObject_Repr(obj); } @@ -2175,8 +2174,8 @@ reject non-numeric types. [clinic start generated code]*/ static PyObject * -builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start) -/*[clinic end generated code: output=33655b248b21d581 input=3b5b7a9d7611c73a]*/ +builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start) +/*[clinic end generated code: output=df758cec7d1d302f input=3b5b7a9d7611c73a]*/ { PyObject *result = start; PyObject *temp, *item, *iter; @@ -2352,9 +2351,9 @@ or ...`` etc. [clinic start generated code]*/ static PyObject * -builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, +builtin_isinstance_impl(PyObject *module, PyObject *obj, PyObject *class_or_tuple) -/*[clinic end generated code: output=f960b7c12dbbeda0 input=ffa743db1daf7549]*/ +/*[clinic end generated code: output=6faf01472c13b003 input=ffa743db1daf7549]*/ { int retval; @@ -2380,9 +2379,9 @@ or ...`` etc. [clinic start generated code]*/ static PyObject * -builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, +builtin_issubclass_impl(PyObject *module, PyObject *cls, PyObject *class_or_tuple) -/*[clinic end generated code: output=8b012a151940bbf2 input=af5f35e9ceaddaf6]*/ +/*[clinic end generated code: output=358412410cd7a250 input=af5f35e9ceaddaf6]*/ { int retval; -- cgit v1.2.1 From 45851bf953d25ba9dc728ef1723da324dfad9433 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 25 Aug 2016 21:11:50 -0700 Subject: Issue 19504: Change "customise" to "customize" American spelling. --- Python/bltinmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index eedd7c3c3c..9e35eb2a13 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2068,7 +2068,7 @@ sorted as builtin_sorted Return a new list containing all items from the iterable in ascending order. -A custom key function can be supplied to customise the sort order, and the +A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order. [end disabled clinic input]*/ @@ -2078,7 +2078,7 @@ PyDoc_STRVAR(builtin_sorted__doc__, "\n" "Return a new list containing all items from the iterable in ascending order.\n" "\n" -"A custom key function can be supplied to customise the sort order, and the\n" +"A custom key function can be supplied to customize the sort order, and the\n" "reverse flag can be set to request the result in descending order."); #define BUILTIN_SORTED_METHODDEF \ -- cgit v1.2.1 From fa43a9a9a4e010c6114ed23eff8a2275980d924b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 3 Sep 2016 01:55:11 -0700 Subject: Issue 27936: Fix inconsistent round() behavior between float and int --- Python/bltinmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 9e35eb2a13..9f5db2afe1 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2039,7 +2039,7 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds) return NULL; } - if (ndigits == NULL) + if (ndigits == NULL || ndigits == Py_None) result = PyObject_CallFunctionObjArgs(round, NULL); else result = PyObject_CallFunctionObjArgs(round, ndigits, NULL); -- cgit v1.2.1