blob: 529274fd5ceb5c5cb523b42a7f293cc02f28c09d [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"
80"format_spec defaults to the empty string");
81
82#define BUILTIN_FORMAT_METHODDEF \
83 {"format", (PyCFunction)builtin_format, METH_VARARGS, builtin_format__doc__},
84
85static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030086builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030087
88static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030089builtin_format(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030090{
91 PyObject *return_value = NULL;
92 PyObject *value;
93 PyObject *format_spec = NULL;
94
Serhiy Storchaka247789c2015-04-24 00:40:51 +030095 if (!PyArg_ParseTuple(args, "O|U:format",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030096 &value, &format_spec)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030097 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030098 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030099 return_value = builtin_format_impl(module, value, format_spec);
100
101exit:
102 return return_value;
103}
104
105PyDoc_STRVAR(builtin_chr__doc__,
106"chr($module, i, /)\n"
107"--\n"
108"\n"
109"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
110
111#define BUILTIN_CHR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300112 {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300113
114static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300115builtin_chr_impl(PyObject *module, int i);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300116
117static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300118builtin_chr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300119{
120 PyObject *return_value = NULL;
121 int i;
122
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300123 if (!PyArg_Parse(arg, "i:chr", &i)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300124 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300125 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300126 return_value = builtin_chr_impl(module, i);
127
128exit:
129 return return_value;
130}
131
132PyDoc_STRVAR(builtin_compile__doc__,
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300133"compile($module, /, source, filename, mode, flags=0,\n"
134" dont_inherit=False, optimize=-1)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300135"--\n"
136"\n"
137"Compile source into a code object that can be executed by exec() or eval().\n"
138"\n"
139"The source code may represent a Python module, statement or expression.\n"
140"The filename will be used for run-time error messages.\n"
141"The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
142"single (interactive) statement, or \'eval\' to compile an expression.\n"
143"The flags argument, if present, controls which future statements influence\n"
144"the compilation of the code.\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300145"The dont_inherit argument, if true, stops the compilation inheriting\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300146"the effects of any future statements in effect in the code calling\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300147"compile; if absent or false these statements do influence the compilation,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300148"in addition to any features explicitly specified.");
149
150#define BUILTIN_COMPILE_METHODDEF \
151 {"compile", (PyCFunction)builtin_compile, METH_VARARGS|METH_KEYWORDS, builtin_compile__doc__},
152
153static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300154builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
155 const char *mode, int flags, int dont_inherit,
156 int optimize);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300157
158static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300159builtin_compile(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300160{
161 PyObject *return_value = NULL;
162 static char *_keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL};
163 PyObject *source;
164 PyObject *filename;
165 const char *mode;
166 int flags = 0;
167 int dont_inherit = 0;
168 int optimize = -1;
169
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300170 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO&s|iii:compile", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300171 &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300172 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300173 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300174 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize);
175
176exit:
177 return return_value;
178}
179
180PyDoc_STRVAR(builtin_divmod__doc__,
181"divmod($module, x, y, /)\n"
182"--\n"
183"\n"
Serhiy Storchakadf071732016-05-01 20:33:24 +0300184"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300185
186#define BUILTIN_DIVMOD_METHODDEF \
187 {"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__},
188
189static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300190builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300191
192static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300193builtin_divmod(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300194{
195 PyObject *return_value = NULL;
196 PyObject *x;
197 PyObject *y;
198
199 if (!PyArg_UnpackTuple(args, "divmod",
200 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300201 &x, &y)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300202 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300203 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300204 return_value = builtin_divmod_impl(module, x, y);
205
206exit:
207 return return_value;
208}
209
210PyDoc_STRVAR(builtin_eval__doc__,
211"eval($module, source, globals=None, locals=None, /)\n"
212"--\n"
213"\n"
214"Evaluate the given source in the context of globals and locals.\n"
215"\n"
216"The source may be a string representing a Python expression\n"
217"or a code object as returned by compile().\n"
218"The globals must be a dictionary and locals can be any mapping,\n"
219"defaulting to the current globals and locals.\n"
220"If only globals is given, locals defaults to it.");
221
222#define BUILTIN_EVAL_METHODDEF \
223 {"eval", (PyCFunction)builtin_eval, METH_VARARGS, builtin_eval__doc__},
224
225static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300226builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400227 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300228
229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300230builtin_eval(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300231{
232 PyObject *return_value = NULL;
233 PyObject *source;
234 PyObject *globals = Py_None;
235 PyObject *locals = Py_None;
236
237 if (!PyArg_UnpackTuple(args, "eval",
238 1, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300239 &source, &globals, &locals)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300240 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300241 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300242 return_value = builtin_eval_impl(module, source, globals, locals);
243
244exit:
245 return return_value;
246}
247
248PyDoc_STRVAR(builtin_exec__doc__,
249"exec($module, source, globals=None, locals=None, /)\n"
250"--\n"
251"\n"
252"Execute the given source in the context of globals and locals.\n"
253"\n"
254"The source may be a string representing one or more Python statements\n"
255"or a code object as returned by compile().\n"
256"The globals must be a dictionary and locals can be any mapping,\n"
257"defaulting to the current globals and locals.\n"
258"If only globals is given, locals defaults to it.");
259
260#define BUILTIN_EXEC_METHODDEF \
261 {"exec", (PyCFunction)builtin_exec, METH_VARARGS, builtin_exec__doc__},
262
263static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300264builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400265 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300266
267static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300268builtin_exec(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300269{
270 PyObject *return_value = NULL;
271 PyObject *source;
272 PyObject *globals = Py_None;
273 PyObject *locals = Py_None;
274
275 if (!PyArg_UnpackTuple(args, "exec",
276 1, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300277 &source, &globals, &locals)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300278 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300279 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300280 return_value = builtin_exec_impl(module, source, globals, locals);
281
282exit:
283 return return_value;
284}
285
286PyDoc_STRVAR(builtin_globals__doc__,
287"globals($module, /)\n"
288"--\n"
289"\n"
290"Return the dictionary containing the current scope\'s global variables.\n"
291"\n"
292"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
293"global scope and vice-versa.");
294
295#define BUILTIN_GLOBALS_METHODDEF \
296 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
297
298static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300299builtin_globals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300300
301static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300302builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300303{
304 return builtin_globals_impl(module);
305}
306
307PyDoc_STRVAR(builtin_hasattr__doc__,
308"hasattr($module, obj, name, /)\n"
309"--\n"
310"\n"
311"Return whether the object has an attribute with the given name.\n"
312"\n"
313"This is done by calling getattr(obj, name) and catching AttributeError.");
314
315#define BUILTIN_HASATTR_METHODDEF \
316 {"hasattr", (PyCFunction)builtin_hasattr, METH_VARARGS, builtin_hasattr__doc__},
317
318static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300319builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300320
321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300322builtin_hasattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300323{
324 PyObject *return_value = NULL;
325 PyObject *obj;
326 PyObject *name;
327
328 if (!PyArg_UnpackTuple(args, "hasattr",
329 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300330 &obj, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300331 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300332 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300333 return_value = builtin_hasattr_impl(module, obj, name);
334
335exit:
336 return return_value;
337}
338
339PyDoc_STRVAR(builtin_id__doc__,
340"id($module, obj, /)\n"
341"--\n"
342"\n"
343"Return the identity of an object.\n"
344"\n"
345"This is guaranteed to be unique among simultaneously existing objects.\n"
346"(CPython uses the object\'s memory address.)");
347
348#define BUILTIN_ID_METHODDEF \
349 {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
350
351PyDoc_STRVAR(builtin_setattr__doc__,
352"setattr($module, obj, name, value, /)\n"
353"--\n"
354"\n"
355"Sets the named attribute on the given object to the specified value.\n"
356"\n"
357"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
358
359#define BUILTIN_SETATTR_METHODDEF \
360 {"setattr", (PyCFunction)builtin_setattr, METH_VARARGS, builtin_setattr__doc__},
361
362static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300363builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
Larry Hastings89964c42015-04-14 18:07:59 -0400364 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300365
366static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300367builtin_setattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300368{
369 PyObject *return_value = NULL;
370 PyObject *obj;
371 PyObject *name;
372 PyObject *value;
373
374 if (!PyArg_UnpackTuple(args, "setattr",
375 3, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300376 &obj, &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300377 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300378 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300379 return_value = builtin_setattr_impl(module, obj, name, value);
380
381exit:
382 return return_value;
383}
384
385PyDoc_STRVAR(builtin_delattr__doc__,
386"delattr($module, obj, name, /)\n"
387"--\n"
388"\n"
389"Deletes the named attribute from the given object.\n"
390"\n"
391"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
392
393#define BUILTIN_DELATTR_METHODDEF \
394 {"delattr", (PyCFunction)builtin_delattr, METH_VARARGS, builtin_delattr__doc__},
395
396static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300397builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300398
399static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300400builtin_delattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300401{
402 PyObject *return_value = NULL;
403 PyObject *obj;
404 PyObject *name;
405
406 if (!PyArg_UnpackTuple(args, "delattr",
407 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300408 &obj, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300409 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300410 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300411 return_value = builtin_delattr_impl(module, obj, name);
412
413exit:
414 return return_value;
415}
416
417PyDoc_STRVAR(builtin_hash__doc__,
418"hash($module, obj, /)\n"
419"--\n"
420"\n"
421"Return the hash value for the given object.\n"
422"\n"
423"Two objects that compare equal must also have the same hash value, but the\n"
424"reverse is not necessarily true.");
425
426#define BUILTIN_HASH_METHODDEF \
427 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
428
429PyDoc_STRVAR(builtin_hex__doc__,
430"hex($module, number, /)\n"
431"--\n"
432"\n"
433"Return the hexadecimal representation of an integer.\n"
434"\n"
435" >>> hex(12648430)\n"
436" \'0xc0ffee\'");
437
438#define BUILTIN_HEX_METHODDEF \
439 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
440
441PyDoc_STRVAR(builtin_len__doc__,
442"len($module, obj, /)\n"
443"--\n"
444"\n"
445"Return the number of items in a container.");
446
447#define BUILTIN_LEN_METHODDEF \
448 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
449
450PyDoc_STRVAR(builtin_locals__doc__,
451"locals($module, /)\n"
452"--\n"
453"\n"
454"Return a dictionary containing the current scope\'s local variables.\n"
455"\n"
456"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
457"the local scope and vice-versa is *implementation dependent* and not\n"
458"covered by any backwards compatibility guarantees.");
459
460#define BUILTIN_LOCALS_METHODDEF \
461 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
462
463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300464builtin_locals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300465
466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300467builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300468{
469 return builtin_locals_impl(module);
470}
471
472PyDoc_STRVAR(builtin_oct__doc__,
473"oct($module, number, /)\n"
474"--\n"
475"\n"
476"Return the octal representation of an integer.\n"
477"\n"
478" >>> oct(342391)\n"
479" \'0o1234567\'");
480
481#define BUILTIN_OCT_METHODDEF \
482 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
483
484PyDoc_STRVAR(builtin_ord__doc__,
485"ord($module, c, /)\n"
486"--\n"
487"\n"
488"Return the Unicode code point for a one-character string.");
489
490#define BUILTIN_ORD_METHODDEF \
491 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
492
493PyDoc_STRVAR(builtin_pow__doc__,
494"pow($module, x, y, z=None, /)\n"
495"--\n"
496"\n"
497"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
498"\n"
499"Some types, such as ints, are able to use a more efficient algorithm when\n"
500"invoked using the three argument form.");
501
502#define BUILTIN_POW_METHODDEF \
503 {"pow", (PyCFunction)builtin_pow, METH_VARARGS, builtin_pow__doc__},
504
505static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300506builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300507
508static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300509builtin_pow(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300510{
511 PyObject *return_value = NULL;
512 PyObject *x;
513 PyObject *y;
514 PyObject *z = Py_None;
515
516 if (!PyArg_UnpackTuple(args, "pow",
517 2, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300518 &x, &y, &z)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300519 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300520 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300521 return_value = builtin_pow_impl(module, x, y, z);
522
523exit:
524 return return_value;
525}
526
527PyDoc_STRVAR(builtin_input__doc__,
528"input($module, prompt=None, /)\n"
529"--\n"
530"\n"
531"Read a string from standard input. The trailing newline is stripped.\n"
532"\n"
533"The prompt string, if given, is printed to standard output without a\n"
534"trailing newline before reading input.\n"
535"\n"
536"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
537"On *nix systems, readline is used if available.");
538
539#define BUILTIN_INPUT_METHODDEF \
540 {"input", (PyCFunction)builtin_input, METH_VARARGS, builtin_input__doc__},
541
542static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300543builtin_input_impl(PyObject *module, PyObject *prompt);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300544
545static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300546builtin_input(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300547{
548 PyObject *return_value = NULL;
549 PyObject *prompt = NULL;
550
551 if (!PyArg_UnpackTuple(args, "input",
552 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300553 &prompt)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300554 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300555 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300556 return_value = builtin_input_impl(module, prompt);
557
558exit:
559 return return_value;
560}
561
562PyDoc_STRVAR(builtin_repr__doc__,
563"repr($module, obj, /)\n"
564"--\n"
565"\n"
566"Return the canonical string representation of the object.\n"
567"\n"
568"For many object types, including most builtins, eval(repr(obj)) == obj.");
569
570#define BUILTIN_REPR_METHODDEF \
571 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
572
573PyDoc_STRVAR(builtin_sum__doc__,
574"sum($module, iterable, start=0, /)\n"
575"--\n"
576"\n"
577"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
578"\n"
579"When the iterable is empty, return the start value.\n"
580"This function is intended specifically for use with numeric values and may\n"
581"reject non-numeric types.");
582
583#define BUILTIN_SUM_METHODDEF \
584 {"sum", (PyCFunction)builtin_sum, METH_VARARGS, builtin_sum__doc__},
585
586static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300587builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300588
589static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300590builtin_sum(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300591{
592 PyObject *return_value = NULL;
593 PyObject *iterable;
594 PyObject *start = NULL;
595
596 if (!PyArg_UnpackTuple(args, "sum",
597 1, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300598 &iterable, &start)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300599 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300600 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300601 return_value = builtin_sum_impl(module, iterable, start);
602
603exit:
604 return return_value;
605}
606
607PyDoc_STRVAR(builtin_isinstance__doc__,
608"isinstance($module, obj, class_or_tuple, /)\n"
609"--\n"
610"\n"
611"Return whether an object is an instance of a class or of a subclass thereof.\n"
612"\n"
613"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
614"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
615"or ...`` etc.");
616
617#define BUILTIN_ISINSTANCE_METHODDEF \
618 {"isinstance", (PyCFunction)builtin_isinstance, METH_VARARGS, builtin_isinstance__doc__},
619
620static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300621builtin_isinstance_impl(PyObject *module, PyObject *obj,
Larry Hastings89964c42015-04-14 18:07:59 -0400622 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300623
624static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300625builtin_isinstance(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300626{
627 PyObject *return_value = NULL;
628 PyObject *obj;
629 PyObject *class_or_tuple;
630
631 if (!PyArg_UnpackTuple(args, "isinstance",
632 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300633 &obj, &class_or_tuple)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300634 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300635 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300636 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
637
638exit:
639 return return_value;
640}
641
642PyDoc_STRVAR(builtin_issubclass__doc__,
643"issubclass($module, cls, class_or_tuple, /)\n"
644"--\n"
645"\n"
646"Return whether \'cls\' is a derived from another class or is the same class.\n"
647"\n"
648"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
649"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
650"or ...`` etc.");
651
652#define BUILTIN_ISSUBCLASS_METHODDEF \
653 {"issubclass", (PyCFunction)builtin_issubclass, METH_VARARGS, builtin_issubclass__doc__},
654
655static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300656builtin_issubclass_impl(PyObject *module, PyObject *cls,
Larry Hastings89964c42015-04-14 18:07:59 -0400657 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300658
659static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300660builtin_issubclass(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300661{
662 PyObject *return_value = NULL;
663 PyObject *cls;
664 PyObject *class_or_tuple;
665
666 if (!PyArg_UnpackTuple(args, "issubclass",
667 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300668 &cls, &class_or_tuple)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300669 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300670 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300671 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
672
673exit:
674 return return_value;
675}
Serhiy Storchaka2954f832016-07-07 18:20:03 +0300676/*[clinic end generated code: output=6ab37e6c6d2e7b19 input=a9049054013a1b77]*/