blob: 0ed11bceeb87e22459a3fb853929a71a6ed1cc6f [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(builtin_abs__doc__,
6"abs($module, x, /)\n"
7"--\n"
8"\n"
9"Return the absolute value of the argument.");
10
11#define BUILTIN_ABS_METHODDEF \
12 {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__},
13
14PyDoc_STRVAR(builtin_all__doc__,
15"all($module, iterable, /)\n"
16"--\n"
17"\n"
18"Return True if bool(x) is True for all values x in the iterable.\n"
19"\n"
20"If the iterable is empty, return True.");
21
22#define BUILTIN_ALL_METHODDEF \
23 {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__},
24
25PyDoc_STRVAR(builtin_any__doc__,
26"any($module, iterable, /)\n"
27"--\n"
28"\n"
29"Return True if bool(x) is True for any x in the iterable.\n"
30"\n"
31"If the iterable is empty, return False.");
32
33#define BUILTIN_ANY_METHODDEF \
34 {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__},
35
36PyDoc_STRVAR(builtin_ascii__doc__,
37"ascii($module, obj, /)\n"
38"--\n"
39"\n"
40"Return an ASCII-only representation of an object.\n"
41"\n"
42"As repr(), return a string containing a printable representation of an\n"
43"object, but escape the non-ASCII characters in the string returned by\n"
44"repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n"
45"to that returned by repr() in Python 2.");
46
47#define BUILTIN_ASCII_METHODDEF \
48 {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__},
49
50PyDoc_STRVAR(builtin_bin__doc__,
51"bin($module, number, /)\n"
52"--\n"
53"\n"
54"Return the binary representation of an integer.\n"
55"\n"
56" >>> bin(2796202)\n"
57" \'0b1010101010101010101010\'");
58
59#define BUILTIN_BIN_METHODDEF \
60 {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__},
61
62PyDoc_STRVAR(builtin_callable__doc__,
63"callable($module, obj, /)\n"
64"--\n"
65"\n"
66"Return whether the object is callable (i.e., some kind of function).\n"
67"\n"
68"Note that classes are callable, as are instances of classes with a\n"
69"__call__() method.");
70
71#define BUILTIN_CALLABLE_METHODDEF \
72 {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__},
73
74PyDoc_STRVAR(builtin_format__doc__,
75"format($module, value, format_spec=\'\', /)\n"
76"--\n"
77"\n"
78"Return value.__format__(format_spec)\n"
79"\n"
Amit Kumar2e6bb442017-05-29 06:32:26 +053080"format_spec defaults to the empty string.\n"
81"See the Format Specification Mini-Language section of help(\'FORMATTING\') for\n"
82"details.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030083
84#define BUILTIN_FORMAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020085 {"format", (PyCFunction)(void(*)(void))builtin_format, METH_FASTCALL, builtin_format__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030086
87static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030088builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030089
90static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020091builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030092{
93 PyObject *return_value = NULL;
94 PyObject *value;
95 PyObject *format_spec = NULL;
96
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020097 if (!_PyArg_CheckPositional("format", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010098 goto exit;
99 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200100 value = args[0];
101 if (nargs < 2) {
102 goto skip_optional;
103 }
104 if (!PyUnicode_Check(args[1])) {
105 _PyArg_BadArgument("format", 2, "str", args[1]);
106 goto exit;
107 }
108 if (PyUnicode_READY(args[1]) == -1) {
109 goto exit;
110 }
111 format_spec = args[1];
112skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300113 return_value = builtin_format_impl(module, value, format_spec);
114
115exit:
116 return return_value;
117}
118
119PyDoc_STRVAR(builtin_chr__doc__,
120"chr($module, i, /)\n"
121"--\n"
122"\n"
123"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
124
125#define BUILTIN_CHR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300126 {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300127
128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300129builtin_chr_impl(PyObject *module, int i);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130
131static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300132builtin_chr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300133{
134 PyObject *return_value = NULL;
135 int i;
136
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200137 if (PyFloat_Check(arg)) {
138 PyErr_SetString(PyExc_TypeError,
139 "integer argument expected, got float" );
140 goto exit;
141 }
142 i = _PyLong_AsInt(arg);
143 if (i == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300144 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300145 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300146 return_value = builtin_chr_impl(module, i);
147
148exit:
149 return return_value;
150}
151
152PyDoc_STRVAR(builtin_compile__doc__,
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300153"compile($module, /, source, filename, mode, flags=0,\n"
Guido van Rossum495da292019-03-07 12:38:08 -0800154" dont_inherit=False, optimize=-1, feature_version=-1)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300155"--\n"
156"\n"
157"Compile source into a code object that can be executed by exec() or eval().\n"
158"\n"
159"The source code may represent a Python module, statement or expression.\n"
160"The filename will be used for run-time error messages.\n"
161"The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
162"single (interactive) statement, or \'eval\' to compile an expression.\n"
163"The flags argument, if present, controls which future statements influence\n"
164"the compilation of the code.\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300165"The dont_inherit argument, if true, stops the compilation inheriting\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300166"the effects of any future statements in effect in the code calling\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300167"compile; if absent or false these statements do influence the compilation,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300168"in addition to any features explicitly specified.");
169
170#define BUILTIN_COMPILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200171 {"compile", (PyCFunction)(void(*)(void))builtin_compile, METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300172
173static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300174builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
175 const char *mode, int flags, int dont_inherit,
Guido van Rossum495da292019-03-07 12:38:08 -0800176 int optimize, int feature_version);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300177
178static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200179builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300180{
181 PyObject *return_value = NULL;
Guido van Rossum495da292019-03-07 12:38:08 -0800182 static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "feature_version", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200183 static _PyArg_Parser _parser = {NULL, _keywords, "compile", 0};
184 PyObject *argsbuf[7];
185 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300186 PyObject *source;
187 PyObject *filename;
188 const char *mode;
189 int flags = 0;
190 int dont_inherit = 0;
191 int optimize = -1;
Guido van Rossum495da292019-03-07 12:38:08 -0800192 int feature_version = -1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300193
Serhiy Storchaka31913912019-03-14 10:32:22 +0200194 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 7, 0, argsbuf);
195 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300196 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300197 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200198 source = args[0];
199 if (!PyUnicode_FSDecoder(args[1], &filename)) {
200 goto exit;
201 }
202 if (!PyUnicode_Check(args[2])) {
203 _PyArg_BadArgument("compile", 3, "str", args[2]);
204 goto exit;
205 }
206 Py_ssize_t mode_length;
207 mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length);
208 if (mode == NULL) {
209 goto exit;
210 }
211 if (strlen(mode) != (size_t)mode_length) {
212 PyErr_SetString(PyExc_ValueError, "embedded null character");
213 goto exit;
214 }
215 if (!noptargs) {
216 goto skip_optional_pos;
217 }
218 if (args[3]) {
219 if (PyFloat_Check(args[3])) {
220 PyErr_SetString(PyExc_TypeError,
221 "integer argument expected, got float" );
222 goto exit;
223 }
224 flags = _PyLong_AsInt(args[3]);
225 if (flags == -1 && PyErr_Occurred()) {
226 goto exit;
227 }
228 if (!--noptargs) {
229 goto skip_optional_pos;
230 }
231 }
232 if (args[4]) {
233 if (PyFloat_Check(args[4])) {
234 PyErr_SetString(PyExc_TypeError,
235 "integer argument expected, got float" );
236 goto exit;
237 }
238 dont_inherit = _PyLong_AsInt(args[4]);
239 if (dont_inherit == -1 && PyErr_Occurred()) {
240 goto exit;
241 }
242 if (!--noptargs) {
243 goto skip_optional_pos;
244 }
245 }
246 if (args[5]) {
247 if (PyFloat_Check(args[5])) {
248 PyErr_SetString(PyExc_TypeError,
249 "integer argument expected, got float" );
250 goto exit;
251 }
252 optimize = _PyLong_AsInt(args[5]);
253 if (optimize == -1 && PyErr_Occurred()) {
254 goto exit;
255 }
256 if (!--noptargs) {
257 goto skip_optional_pos;
258 }
259 }
260 if (PyFloat_Check(args[6])) {
261 PyErr_SetString(PyExc_TypeError,
262 "integer argument expected, got float" );
263 goto exit;
264 }
265 feature_version = _PyLong_AsInt(args[6]);
266 if (feature_version == -1 && PyErr_Occurred()) {
267 goto exit;
268 }
269skip_optional_pos:
Guido van Rossum495da292019-03-07 12:38:08 -0800270 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300271
272exit:
273 return return_value;
274}
275
276PyDoc_STRVAR(builtin_divmod__doc__,
277"divmod($module, x, y, /)\n"
278"--\n"
279"\n"
Serhiy Storchakadf071732016-05-01 20:33:24 +0300280"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300281
282#define BUILTIN_DIVMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200283 {"divmod", (PyCFunction)(void(*)(void))builtin_divmod, METH_FASTCALL, builtin_divmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300284
285static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300286builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300287
288static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200289builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300290{
291 PyObject *return_value = NULL;
292 PyObject *x;
293 PyObject *y;
294
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200295 if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100296 goto exit;
297 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200298 x = args[0];
299 y = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300300 return_value = builtin_divmod_impl(module, x, y);
301
302exit:
303 return return_value;
304}
305
306PyDoc_STRVAR(builtin_eval__doc__,
307"eval($module, source, globals=None, locals=None, /)\n"
308"--\n"
309"\n"
310"Evaluate the given source in the context of globals and locals.\n"
311"\n"
312"The source may be a string representing a Python expression\n"
313"or a code object as returned by compile().\n"
314"The globals must be a dictionary and locals can be any mapping,\n"
315"defaulting to the current globals and locals.\n"
316"If only globals is given, locals defaults to it.");
317
318#define BUILTIN_EVAL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200319 {"eval", (PyCFunction)(void(*)(void))builtin_eval, METH_FASTCALL, builtin_eval__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300320
321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300322builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400323 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300324
325static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200326builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300327{
328 PyObject *return_value = NULL;
329 PyObject *source;
330 PyObject *globals = Py_None;
331 PyObject *locals = Py_None;
332
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200333 if (!_PyArg_CheckPositional("eval", nargs, 1, 3)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100334 goto exit;
335 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200336 source = args[0];
337 if (nargs < 2) {
338 goto skip_optional;
339 }
340 globals = args[1];
341 if (nargs < 3) {
342 goto skip_optional;
343 }
344 locals = args[2];
345skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346 return_value = builtin_eval_impl(module, source, globals, locals);
347
348exit:
349 return return_value;
350}
351
352PyDoc_STRVAR(builtin_exec__doc__,
353"exec($module, source, globals=None, locals=None, /)\n"
354"--\n"
355"\n"
356"Execute the given source in the context of globals and locals.\n"
357"\n"
358"The source may be a string representing one or more Python statements\n"
359"or a code object as returned by compile().\n"
360"The globals must be a dictionary and locals can be any mapping,\n"
361"defaulting to the current globals and locals.\n"
362"If only globals is given, locals defaults to it.");
363
364#define BUILTIN_EXEC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200365 {"exec", (PyCFunction)(void(*)(void))builtin_exec, METH_FASTCALL, builtin_exec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300366
367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300368builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400369 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300370
371static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200372builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300373{
374 PyObject *return_value = NULL;
375 PyObject *source;
376 PyObject *globals = Py_None;
377 PyObject *locals = Py_None;
378
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200379 if (!_PyArg_CheckPositional("exec", nargs, 1, 3)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100380 goto exit;
381 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200382 source = args[0];
383 if (nargs < 2) {
384 goto skip_optional;
385 }
386 globals = args[1];
387 if (nargs < 3) {
388 goto skip_optional;
389 }
390 locals = args[2];
391skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300392 return_value = builtin_exec_impl(module, source, globals, locals);
393
394exit:
395 return return_value;
396}
397
398PyDoc_STRVAR(builtin_globals__doc__,
399"globals($module, /)\n"
400"--\n"
401"\n"
402"Return the dictionary containing the current scope\'s global variables.\n"
403"\n"
404"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
405"global scope and vice-versa.");
406
407#define BUILTIN_GLOBALS_METHODDEF \
408 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
409
410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300411builtin_globals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300412
413static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300414builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300415{
416 return builtin_globals_impl(module);
417}
418
419PyDoc_STRVAR(builtin_hasattr__doc__,
420"hasattr($module, obj, name, /)\n"
421"--\n"
422"\n"
423"Return whether the object has an attribute with the given name.\n"
424"\n"
425"This is done by calling getattr(obj, name) and catching AttributeError.");
426
427#define BUILTIN_HASATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200428 {"hasattr", (PyCFunction)(void(*)(void))builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300429
430static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300431builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300432
433static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200434builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300435{
436 PyObject *return_value = NULL;
437 PyObject *obj;
438 PyObject *name;
439
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200440 if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100441 goto exit;
442 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200443 obj = args[0];
444 name = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300445 return_value = builtin_hasattr_impl(module, obj, name);
446
447exit:
448 return return_value;
449}
450
451PyDoc_STRVAR(builtin_id__doc__,
452"id($module, obj, /)\n"
453"--\n"
454"\n"
455"Return the identity of an object.\n"
456"\n"
457"This is guaranteed to be unique among simultaneously existing objects.\n"
458"(CPython uses the object\'s memory address.)");
459
460#define BUILTIN_ID_METHODDEF \
461 {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
462
463PyDoc_STRVAR(builtin_setattr__doc__,
464"setattr($module, obj, name, value, /)\n"
465"--\n"
466"\n"
467"Sets the named attribute on the given object to the specified value.\n"
468"\n"
469"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
470
471#define BUILTIN_SETATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200472 {"setattr", (PyCFunction)(void(*)(void))builtin_setattr, METH_FASTCALL, builtin_setattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300473
474static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300475builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
Larry Hastings89964c42015-04-14 18:07:59 -0400476 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300477
478static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200479builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300480{
481 PyObject *return_value = NULL;
482 PyObject *obj;
483 PyObject *name;
484 PyObject *value;
485
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200486 if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100487 goto exit;
488 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200489 obj = args[0];
490 name = args[1];
491 value = args[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300492 return_value = builtin_setattr_impl(module, obj, name, value);
493
494exit:
495 return return_value;
496}
497
498PyDoc_STRVAR(builtin_delattr__doc__,
499"delattr($module, obj, name, /)\n"
500"--\n"
501"\n"
502"Deletes the named attribute from the given object.\n"
503"\n"
504"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
505
506#define BUILTIN_DELATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200507 {"delattr", (PyCFunction)(void(*)(void))builtin_delattr, METH_FASTCALL, builtin_delattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300508
509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300510builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511
512static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200513builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300514{
515 PyObject *return_value = NULL;
516 PyObject *obj;
517 PyObject *name;
518
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200519 if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100520 goto exit;
521 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200522 obj = args[0];
523 name = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300524 return_value = builtin_delattr_impl(module, obj, name);
525
526exit:
527 return return_value;
528}
529
530PyDoc_STRVAR(builtin_hash__doc__,
531"hash($module, obj, /)\n"
532"--\n"
533"\n"
534"Return the hash value for the given object.\n"
535"\n"
536"Two objects that compare equal must also have the same hash value, but the\n"
537"reverse is not necessarily true.");
538
539#define BUILTIN_HASH_METHODDEF \
540 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
541
542PyDoc_STRVAR(builtin_hex__doc__,
543"hex($module, number, /)\n"
544"--\n"
545"\n"
546"Return the hexadecimal representation of an integer.\n"
547"\n"
548" >>> hex(12648430)\n"
549" \'0xc0ffee\'");
550
551#define BUILTIN_HEX_METHODDEF \
552 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
553
554PyDoc_STRVAR(builtin_len__doc__,
555"len($module, obj, /)\n"
556"--\n"
557"\n"
558"Return the number of items in a container.");
559
560#define BUILTIN_LEN_METHODDEF \
561 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
562
563PyDoc_STRVAR(builtin_locals__doc__,
564"locals($module, /)\n"
565"--\n"
566"\n"
567"Return a dictionary containing the current scope\'s local variables.\n"
568"\n"
569"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
570"the local scope and vice-versa is *implementation dependent* and not\n"
571"covered by any backwards compatibility guarantees.");
572
573#define BUILTIN_LOCALS_METHODDEF \
574 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
575
576static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300577builtin_locals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300578
579static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300580builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300581{
582 return builtin_locals_impl(module);
583}
584
585PyDoc_STRVAR(builtin_oct__doc__,
586"oct($module, number, /)\n"
587"--\n"
588"\n"
589"Return the octal representation of an integer.\n"
590"\n"
591" >>> oct(342391)\n"
592" \'0o1234567\'");
593
594#define BUILTIN_OCT_METHODDEF \
595 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
596
597PyDoc_STRVAR(builtin_ord__doc__,
598"ord($module, c, /)\n"
599"--\n"
600"\n"
601"Return the Unicode code point for a one-character string.");
602
603#define BUILTIN_ORD_METHODDEF \
604 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
605
606PyDoc_STRVAR(builtin_pow__doc__,
607"pow($module, x, y, z=None, /)\n"
608"--\n"
609"\n"
610"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
611"\n"
612"Some types, such as ints, are able to use a more efficient algorithm when\n"
613"invoked using the three argument form.");
614
615#define BUILTIN_POW_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200616 {"pow", (PyCFunction)(void(*)(void))builtin_pow, METH_FASTCALL, builtin_pow__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300617
618static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300619builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300620
621static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200622builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300623{
624 PyObject *return_value = NULL;
625 PyObject *x;
626 PyObject *y;
627 PyObject *z = Py_None;
628
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200629 if (!_PyArg_CheckPositional("pow", nargs, 2, 3)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100630 goto exit;
631 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200632 x = args[0];
633 y = args[1];
634 if (nargs < 3) {
635 goto skip_optional;
636 }
637 z = args[2];
638skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300639 return_value = builtin_pow_impl(module, x, y, z);
640
641exit:
642 return return_value;
643}
644
645PyDoc_STRVAR(builtin_input__doc__,
646"input($module, prompt=None, /)\n"
647"--\n"
648"\n"
649"Read a string from standard input. The trailing newline is stripped.\n"
650"\n"
651"The prompt string, if given, is printed to standard output without a\n"
652"trailing newline before reading input.\n"
653"\n"
654"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
655"On *nix systems, readline is used if available.");
656
657#define BUILTIN_INPUT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200658 {"input", (PyCFunction)(void(*)(void))builtin_input, METH_FASTCALL, builtin_input__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300659
660static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300661builtin_input_impl(PyObject *module, PyObject *prompt);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300662
663static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200664builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300665{
666 PyObject *return_value = NULL;
667 PyObject *prompt = NULL;
668
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200669 if (!_PyArg_CheckPositional("input", nargs, 0, 1)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100670 goto exit;
671 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200672 if (nargs < 1) {
673 goto skip_optional;
674 }
675 prompt = args[0];
676skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300677 return_value = builtin_input_impl(module, prompt);
678
679exit:
680 return return_value;
681}
682
683PyDoc_STRVAR(builtin_repr__doc__,
684"repr($module, obj, /)\n"
685"--\n"
686"\n"
687"Return the canonical string representation of the object.\n"
688"\n"
689"For many object types, including most builtins, eval(repr(obj)) == obj.");
690
691#define BUILTIN_REPR_METHODDEF \
692 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
693
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200694PyDoc_STRVAR(builtin_round__doc__,
695"round($module, /, number, ndigits=None)\n"
696"--\n"
697"\n"
698"Round a number to a given precision in decimal digits.\n"
699"\n"
700"The return value is an integer if ndigits is omitted or None. Otherwise\n"
701"the return value has the same type as the number. ndigits may be negative.");
702
703#define BUILTIN_ROUND_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200704 {"round", (PyCFunction)(void(*)(void))builtin_round, METH_FASTCALL|METH_KEYWORDS, builtin_round__doc__},
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200705
706static PyObject *
707builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits);
708
709static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200710builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200711{
712 PyObject *return_value = NULL;
713 static const char * const _keywords[] = {"number", "ndigits", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200714 static _PyArg_Parser _parser = {NULL, _keywords, "round", 0};
715 PyObject *argsbuf[2];
716 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200717 PyObject *number;
718 PyObject *ndigits = NULL;
719
Serhiy Storchaka31913912019-03-14 10:32:22 +0200720 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
721 if (!args) {
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200722 goto exit;
723 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200724 number = args[0];
725 if (!noptargs) {
726 goto skip_optional_pos;
727 }
728 ndigits = args[1];
729skip_optional_pos:
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200730 return_value = builtin_round_impl(module, number, ndigits);
731
732exit:
733 return return_value;
734}
735
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300736PyDoc_STRVAR(builtin_sum__doc__,
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700737"sum($module, iterable, /, start=0)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300738"--\n"
739"\n"
740"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
741"\n"
742"When the iterable is empty, return the start value.\n"
743"This function is intended specifically for use with numeric values and may\n"
744"reject non-numeric types.");
745
746#define BUILTIN_SUM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200747 {"sum", (PyCFunction)(void(*)(void))builtin_sum, METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300748
749static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300750builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300751
752static PyObject *
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700753builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300754{
755 PyObject *return_value = NULL;
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700756 static const char * const _keywords[] = {"", "start", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200757 static _PyArg_Parser _parser = {NULL, _keywords, "sum", 0};
758 PyObject *argsbuf[2];
759 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300760 PyObject *iterable;
761 PyObject *start = NULL;
762
Serhiy Storchaka31913912019-03-14 10:32:22 +0200763 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
764 if (!args) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100765 goto exit;
766 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200767 iterable = args[0];
768 if (!noptargs) {
769 goto skip_optional_pos;
770 }
771 start = args[1];
772skip_optional_pos:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300773 return_value = builtin_sum_impl(module, iterable, start);
774
775exit:
776 return return_value;
777}
778
779PyDoc_STRVAR(builtin_isinstance__doc__,
780"isinstance($module, obj, class_or_tuple, /)\n"
781"--\n"
782"\n"
783"Return whether an object is an instance of a class or of a subclass thereof.\n"
784"\n"
785"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
786"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
787"or ...`` etc.");
788
789#define BUILTIN_ISINSTANCE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200790 {"isinstance", (PyCFunction)(void(*)(void))builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300791
792static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300793builtin_isinstance_impl(PyObject *module, PyObject *obj,
Larry Hastings89964c42015-04-14 18:07:59 -0400794 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300795
796static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200797builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300798{
799 PyObject *return_value = NULL;
800 PyObject *obj;
801 PyObject *class_or_tuple;
802
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200803 if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100804 goto exit;
805 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200806 obj = args[0];
807 class_or_tuple = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300808 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
809
810exit:
811 return return_value;
812}
813
814PyDoc_STRVAR(builtin_issubclass__doc__,
815"issubclass($module, cls, class_or_tuple, /)\n"
816"--\n"
817"\n"
818"Return whether \'cls\' is a derived from another class or is the same class.\n"
819"\n"
820"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
821"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
822"or ...`` etc.");
823
824#define BUILTIN_ISSUBCLASS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200825 {"issubclass", (PyCFunction)(void(*)(void))builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300826
827static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300828builtin_issubclass_impl(PyObject *module, PyObject *cls,
Larry Hastings89964c42015-04-14 18:07:59 -0400829 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300830
831static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200832builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300833{
834 PyObject *return_value = NULL;
835 PyObject *cls;
836 PyObject *class_or_tuple;
837
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200838 if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100839 goto exit;
840 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200841 cls = args[0];
842 class_or_tuple = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300843 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
844
845exit:
846 return return_value;
847}
Serhiy Storchaka31913912019-03-14 10:32:22 +0200848/*[clinic end generated code: output=3f690311ac556c31 input=a9049054013a1b77]*/