blob: 7f043dac4f386e04d0623e74ccf095bdafe3585a [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
Sylvain74453812017-06-10 06:51:48 +020097 if (!_PyArg_ParseStack(args, nargs, "O|U:format",
98 &value, &format_spec)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010099 goto exit;
100 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300101 return_value = builtin_format_impl(module, value, format_spec);
102
103exit:
104 return return_value;
105}
106
107PyDoc_STRVAR(builtin_chr__doc__,
108"chr($module, i, /)\n"
109"--\n"
110"\n"
111"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
112
113#define BUILTIN_CHR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300114 {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300115
116static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300117builtin_chr_impl(PyObject *module, int i);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300118
119static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300120builtin_chr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300121{
122 PyObject *return_value = NULL;
123 int i;
124
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200125 if (PyFloat_Check(arg)) {
126 PyErr_SetString(PyExc_TypeError,
127 "integer argument expected, got float" );
128 goto exit;
129 }
130 i = _PyLong_AsInt(arg);
131 if (i == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300132 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300133 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300134 return_value = builtin_chr_impl(module, i);
135
136exit:
137 return return_value;
138}
139
140PyDoc_STRVAR(builtin_compile__doc__,
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300141"compile($module, /, source, filename, mode, flags=0,\n"
142" dont_inherit=False, optimize=-1)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300143"--\n"
144"\n"
145"Compile source into a code object that can be executed by exec() or eval().\n"
146"\n"
147"The source code may represent a Python module, statement or expression.\n"
148"The filename will be used for run-time error messages.\n"
149"The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
150"single (interactive) statement, or \'eval\' to compile an expression.\n"
151"The flags argument, if present, controls which future statements influence\n"
152"the compilation of the code.\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300153"The dont_inherit argument, if true, stops the compilation inheriting\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154"the effects of any future statements in effect in the code calling\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300155"compile; if absent or false these statements do influence the compilation,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156"in addition to any features explicitly specified.");
157
158#define BUILTIN_COMPILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200159 {"compile", (PyCFunction)(void(*)(void))builtin_compile, METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300160
161static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300162builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
163 const char *mode, int flags, int dont_inherit,
164 int optimize);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300165
166static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200167builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300168{
169 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300170 static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL};
171 static _PyArg_Parser _parser = {"OO&s|iii:compile", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300172 PyObject *source;
173 PyObject *filename;
174 const char *mode;
175 int flags = 0;
176 int dont_inherit = 0;
177 int optimize = -1;
178
Victor Stinner3e1fad62017-01-17 01:29:01 +0100179 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300180 &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300182 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300183 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize);
184
185exit:
186 return return_value;
187}
188
189PyDoc_STRVAR(builtin_divmod__doc__,
190"divmod($module, x, y, /)\n"
191"--\n"
192"\n"
Serhiy Storchakadf071732016-05-01 20:33:24 +0300193"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300194
195#define BUILTIN_DIVMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200196 {"divmod", (PyCFunction)(void(*)(void))builtin_divmod, METH_FASTCALL, builtin_divmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300197
198static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300199builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300200
201static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200202builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300203{
204 PyObject *return_value = NULL;
205 PyObject *x;
206 PyObject *y;
207
Sylvain74453812017-06-10 06:51:48 +0200208 if (!_PyArg_UnpackStack(args, nargs, "divmod",
209 2, 2,
210 &x, &y)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100211 goto exit;
212 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300213 return_value = builtin_divmod_impl(module, x, y);
214
215exit:
216 return return_value;
217}
218
219PyDoc_STRVAR(builtin_eval__doc__,
220"eval($module, source, globals=None, locals=None, /)\n"
221"--\n"
222"\n"
223"Evaluate the given source in the context of globals and locals.\n"
224"\n"
225"The source may be a string representing a Python expression\n"
226"or a code object as returned by compile().\n"
227"The globals must be a dictionary and locals can be any mapping,\n"
228"defaulting to the current globals and locals.\n"
229"If only globals is given, locals defaults to it.");
230
231#define BUILTIN_EVAL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200232 {"eval", (PyCFunction)(void(*)(void))builtin_eval, METH_FASTCALL, builtin_eval__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300233
234static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300235builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400236 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300237
238static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200239builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300240{
241 PyObject *return_value = NULL;
242 PyObject *source;
243 PyObject *globals = Py_None;
244 PyObject *locals = Py_None;
245
Sylvain74453812017-06-10 06:51:48 +0200246 if (!_PyArg_UnpackStack(args, nargs, "eval",
247 1, 3,
248 &source, &globals, &locals)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100249 goto exit;
250 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300251 return_value = builtin_eval_impl(module, source, globals, locals);
252
253exit:
254 return return_value;
255}
256
257PyDoc_STRVAR(builtin_exec__doc__,
258"exec($module, source, globals=None, locals=None, /)\n"
259"--\n"
260"\n"
261"Execute the given source in the context of globals and locals.\n"
262"\n"
263"The source may be a string representing one or more Python statements\n"
264"or a code object as returned by compile().\n"
265"The globals must be a dictionary and locals can be any mapping,\n"
266"defaulting to the current globals and locals.\n"
267"If only globals is given, locals defaults to it.");
268
269#define BUILTIN_EXEC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200270 {"exec", (PyCFunction)(void(*)(void))builtin_exec, METH_FASTCALL, builtin_exec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300271
272static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300273builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400274 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300275
276static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200277builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300278{
279 PyObject *return_value = NULL;
280 PyObject *source;
281 PyObject *globals = Py_None;
282 PyObject *locals = Py_None;
283
Sylvain74453812017-06-10 06:51:48 +0200284 if (!_PyArg_UnpackStack(args, nargs, "exec",
285 1, 3,
286 &source, &globals, &locals)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100287 goto exit;
288 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300289 return_value = builtin_exec_impl(module, source, globals, locals);
290
291exit:
292 return return_value;
293}
294
295PyDoc_STRVAR(builtin_globals__doc__,
296"globals($module, /)\n"
297"--\n"
298"\n"
299"Return the dictionary containing the current scope\'s global variables.\n"
300"\n"
301"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
302"global scope and vice-versa.");
303
304#define BUILTIN_GLOBALS_METHODDEF \
305 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
306
307static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300308builtin_globals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300309
310static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300311builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300312{
313 return builtin_globals_impl(module);
314}
315
316PyDoc_STRVAR(builtin_hasattr__doc__,
317"hasattr($module, obj, name, /)\n"
318"--\n"
319"\n"
320"Return whether the object has an attribute with the given name.\n"
321"\n"
322"This is done by calling getattr(obj, name) and catching AttributeError.");
323
324#define BUILTIN_HASATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200325 {"hasattr", (PyCFunction)(void(*)(void))builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300326
327static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300328builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300329
330static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200331builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300332{
333 PyObject *return_value = NULL;
334 PyObject *obj;
335 PyObject *name;
336
Sylvain74453812017-06-10 06:51:48 +0200337 if (!_PyArg_UnpackStack(args, nargs, "hasattr",
338 2, 2,
339 &obj, &name)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100340 goto exit;
341 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300342 return_value = builtin_hasattr_impl(module, obj, name);
343
344exit:
345 return return_value;
346}
347
348PyDoc_STRVAR(builtin_id__doc__,
349"id($module, obj, /)\n"
350"--\n"
351"\n"
352"Return the identity of an object.\n"
353"\n"
354"This is guaranteed to be unique among simultaneously existing objects.\n"
355"(CPython uses the object\'s memory address.)");
356
357#define BUILTIN_ID_METHODDEF \
358 {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
359
360PyDoc_STRVAR(builtin_setattr__doc__,
361"setattr($module, obj, name, value, /)\n"
362"--\n"
363"\n"
364"Sets the named attribute on the given object to the specified value.\n"
365"\n"
366"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
367
368#define BUILTIN_SETATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200369 {"setattr", (PyCFunction)(void(*)(void))builtin_setattr, METH_FASTCALL, builtin_setattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300370
371static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300372builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
Larry Hastings89964c42015-04-14 18:07:59 -0400373 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300374
375static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200376builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300377{
378 PyObject *return_value = NULL;
379 PyObject *obj;
380 PyObject *name;
381 PyObject *value;
382
Sylvain74453812017-06-10 06:51:48 +0200383 if (!_PyArg_UnpackStack(args, nargs, "setattr",
384 3, 3,
385 &obj, &name, &value)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100386 goto exit;
387 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300388 return_value = builtin_setattr_impl(module, obj, name, value);
389
390exit:
391 return return_value;
392}
393
394PyDoc_STRVAR(builtin_delattr__doc__,
395"delattr($module, obj, name, /)\n"
396"--\n"
397"\n"
398"Deletes the named attribute from the given object.\n"
399"\n"
400"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
401
402#define BUILTIN_DELATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200403 {"delattr", (PyCFunction)(void(*)(void))builtin_delattr, METH_FASTCALL, builtin_delattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300404
405static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300406builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300407
408static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200409builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300410{
411 PyObject *return_value = NULL;
412 PyObject *obj;
413 PyObject *name;
414
Sylvain74453812017-06-10 06:51:48 +0200415 if (!_PyArg_UnpackStack(args, nargs, "delattr",
416 2, 2,
417 &obj, &name)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100418 goto exit;
419 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300420 return_value = builtin_delattr_impl(module, obj, name);
421
422exit:
423 return return_value;
424}
425
426PyDoc_STRVAR(builtin_hash__doc__,
427"hash($module, obj, /)\n"
428"--\n"
429"\n"
430"Return the hash value for the given object.\n"
431"\n"
432"Two objects that compare equal must also have the same hash value, but the\n"
433"reverse is not necessarily true.");
434
435#define BUILTIN_HASH_METHODDEF \
436 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
437
438PyDoc_STRVAR(builtin_hex__doc__,
439"hex($module, number, /)\n"
440"--\n"
441"\n"
442"Return the hexadecimal representation of an integer.\n"
443"\n"
444" >>> hex(12648430)\n"
445" \'0xc0ffee\'");
446
447#define BUILTIN_HEX_METHODDEF \
448 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
449
450PyDoc_STRVAR(builtin_len__doc__,
451"len($module, obj, /)\n"
452"--\n"
453"\n"
454"Return the number of items in a container.");
455
456#define BUILTIN_LEN_METHODDEF \
457 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
458
459PyDoc_STRVAR(builtin_locals__doc__,
460"locals($module, /)\n"
461"--\n"
462"\n"
463"Return a dictionary containing the current scope\'s local variables.\n"
464"\n"
465"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
466"the local scope and vice-versa is *implementation dependent* and not\n"
467"covered by any backwards compatibility guarantees.");
468
469#define BUILTIN_LOCALS_METHODDEF \
470 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
471
472static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300473builtin_locals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300474
475static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300476builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300477{
478 return builtin_locals_impl(module);
479}
480
481PyDoc_STRVAR(builtin_oct__doc__,
482"oct($module, number, /)\n"
483"--\n"
484"\n"
485"Return the octal representation of an integer.\n"
486"\n"
487" >>> oct(342391)\n"
488" \'0o1234567\'");
489
490#define BUILTIN_OCT_METHODDEF \
491 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
492
493PyDoc_STRVAR(builtin_ord__doc__,
494"ord($module, c, /)\n"
495"--\n"
496"\n"
497"Return the Unicode code point for a one-character string.");
498
499#define BUILTIN_ORD_METHODDEF \
500 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
501
502PyDoc_STRVAR(builtin_pow__doc__,
503"pow($module, x, y, z=None, /)\n"
504"--\n"
505"\n"
506"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
507"\n"
508"Some types, such as ints, are able to use a more efficient algorithm when\n"
509"invoked using the three argument form.");
510
511#define BUILTIN_POW_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200512 {"pow", (PyCFunction)(void(*)(void))builtin_pow, METH_FASTCALL, builtin_pow__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300513
514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300515builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300516
517static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200518builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300519{
520 PyObject *return_value = NULL;
521 PyObject *x;
522 PyObject *y;
523 PyObject *z = Py_None;
524
Sylvain74453812017-06-10 06:51:48 +0200525 if (!_PyArg_UnpackStack(args, nargs, "pow",
526 2, 3,
527 &x, &y, &z)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100528 goto exit;
529 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300530 return_value = builtin_pow_impl(module, x, y, z);
531
532exit:
533 return return_value;
534}
535
536PyDoc_STRVAR(builtin_input__doc__,
537"input($module, prompt=None, /)\n"
538"--\n"
539"\n"
540"Read a string from standard input. The trailing newline is stripped.\n"
541"\n"
542"The prompt string, if given, is printed to standard output without a\n"
543"trailing newline before reading input.\n"
544"\n"
545"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
546"On *nix systems, readline is used if available.");
547
548#define BUILTIN_INPUT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200549 {"input", (PyCFunction)(void(*)(void))builtin_input, METH_FASTCALL, builtin_input__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300550
551static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300552builtin_input_impl(PyObject *module, PyObject *prompt);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300553
554static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200555builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300556{
557 PyObject *return_value = NULL;
558 PyObject *prompt = NULL;
559
Sylvain74453812017-06-10 06:51:48 +0200560 if (!_PyArg_UnpackStack(args, nargs, "input",
561 0, 1,
562 &prompt)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100563 goto exit;
564 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300565 return_value = builtin_input_impl(module, prompt);
566
567exit:
568 return return_value;
569}
570
571PyDoc_STRVAR(builtin_repr__doc__,
572"repr($module, obj, /)\n"
573"--\n"
574"\n"
575"Return the canonical string representation of the object.\n"
576"\n"
577"For many object types, including most builtins, eval(repr(obj)) == obj.");
578
579#define BUILTIN_REPR_METHODDEF \
580 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
581
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200582PyDoc_STRVAR(builtin_round__doc__,
583"round($module, /, number, ndigits=None)\n"
584"--\n"
585"\n"
586"Round a number to a given precision in decimal digits.\n"
587"\n"
588"The return value is an integer if ndigits is omitted or None. Otherwise\n"
589"the return value has the same type as the number. ndigits may be negative.");
590
591#define BUILTIN_ROUND_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200592 {"round", (PyCFunction)(void(*)(void))builtin_round, METH_FASTCALL|METH_KEYWORDS, builtin_round__doc__},
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200593
594static PyObject *
595builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits);
596
597static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200598builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200599{
600 PyObject *return_value = NULL;
601 static const char * const _keywords[] = {"number", "ndigits", NULL};
602 static _PyArg_Parser _parser = {"O|O:round", _keywords, 0};
603 PyObject *number;
604 PyObject *ndigits = NULL;
605
606 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
607 &number, &ndigits)) {
608 goto exit;
609 }
610 return_value = builtin_round_impl(module, number, ndigits);
611
612exit:
613 return return_value;
614}
615
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300616PyDoc_STRVAR(builtin_sum__doc__,
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700617"sum($module, iterable, /, start=0)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300618"--\n"
619"\n"
620"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
621"\n"
622"When the iterable is empty, return the start value.\n"
623"This function is intended specifically for use with numeric values and may\n"
624"reject non-numeric types.");
625
626#define BUILTIN_SUM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200627 {"sum", (PyCFunction)(void(*)(void))builtin_sum, METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300628
629static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300630builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300631
632static PyObject *
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700633builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300634{
635 PyObject *return_value = NULL;
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700636 static const char * const _keywords[] = {"", "start", NULL};
637 static _PyArg_Parser _parser = {"O|O:sum", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300638 PyObject *iterable;
639 PyObject *start = NULL;
640
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700641 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Sylvain74453812017-06-10 06:51:48 +0200642 &iterable, &start)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100643 goto exit;
644 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300645 return_value = builtin_sum_impl(module, iterable, start);
646
647exit:
648 return return_value;
649}
650
651PyDoc_STRVAR(builtin_isinstance__doc__,
652"isinstance($module, obj, class_or_tuple, /)\n"
653"--\n"
654"\n"
655"Return whether an object is an instance of a class or of a subclass thereof.\n"
656"\n"
657"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
658"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
659"or ...`` etc.");
660
661#define BUILTIN_ISINSTANCE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200662 {"isinstance", (PyCFunction)(void(*)(void))builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300663
664static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300665builtin_isinstance_impl(PyObject *module, PyObject *obj,
Larry Hastings89964c42015-04-14 18:07:59 -0400666 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300667
668static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200669builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300670{
671 PyObject *return_value = NULL;
672 PyObject *obj;
673 PyObject *class_or_tuple;
674
Sylvain74453812017-06-10 06:51:48 +0200675 if (!_PyArg_UnpackStack(args, nargs, "isinstance",
676 2, 2,
677 &obj, &class_or_tuple)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100678 goto exit;
679 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300680 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
681
682exit:
683 return return_value;
684}
685
686PyDoc_STRVAR(builtin_issubclass__doc__,
687"issubclass($module, cls, class_or_tuple, /)\n"
688"--\n"
689"\n"
690"Return whether \'cls\' is a derived from another class or is the same class.\n"
691"\n"
692"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
693"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
694"or ...`` etc.");
695
696#define BUILTIN_ISSUBCLASS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200697 {"issubclass", (PyCFunction)(void(*)(void))builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300698
699static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300700builtin_issubclass_impl(PyObject *module, PyObject *cls,
Larry Hastings89964c42015-04-14 18:07:59 -0400701 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300702
703static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200704builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300705{
706 PyObject *return_value = NULL;
707 PyObject *cls;
708 PyObject *class_or_tuple;
709
Sylvain74453812017-06-10 06:51:48 +0200710 if (!_PyArg_UnpackStack(args, nargs, "issubclass",
711 2, 2,
712 &cls, &class_or_tuple)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100713 goto exit;
714 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300715 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
716
717exit:
718 return return_value;
719}
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200720/*[clinic end generated code: output=ed300ebf3f6db530 input=a9049054013a1b77]*/