blob: 4c44340ef668e7ce5090f4cef49bcb4382615644 [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;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300162 static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL};
163 static _PyArg_Parser _parser = {"OO&s|iii:compile", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300164 PyObject *source;
165 PyObject *filename;
166 const char *mode;
167 int flags = 0;
168 int dont_inherit = 0;
169 int optimize = -1;
170
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300171 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300172 &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300173 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300174 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300175 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize);
176
177exit:
178 return return_value;
179}
180
181PyDoc_STRVAR(builtin_divmod__doc__,
182"divmod($module, x, y, /)\n"
183"--\n"
184"\n"
Serhiy Storchakadf071732016-05-01 20:33:24 +0300185"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300186
187#define BUILTIN_DIVMOD_METHODDEF \
188 {"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__},
189
190static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300191builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192
193static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300194builtin_divmod(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300195{
196 PyObject *return_value = NULL;
197 PyObject *x;
198 PyObject *y;
199
200 if (!PyArg_UnpackTuple(args, "divmod",
201 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300202 &x, &y)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300203 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300204 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300205 return_value = builtin_divmod_impl(module, x, y);
206
207exit:
208 return return_value;
209}
210
211PyDoc_STRVAR(builtin_eval__doc__,
212"eval($module, source, globals=None, locals=None, /)\n"
213"--\n"
214"\n"
215"Evaluate the given source in the context of globals and locals.\n"
216"\n"
217"The source may be a string representing a Python expression\n"
218"or a code object as returned by compile().\n"
219"The globals must be a dictionary and locals can be any mapping,\n"
220"defaulting to the current globals and locals.\n"
221"If only globals is given, locals defaults to it.");
222
223#define BUILTIN_EVAL_METHODDEF \
224 {"eval", (PyCFunction)builtin_eval, METH_VARARGS, builtin_eval__doc__},
225
226static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300227builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400228 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300229
230static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300231builtin_eval(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300232{
233 PyObject *return_value = NULL;
234 PyObject *source;
235 PyObject *globals = Py_None;
236 PyObject *locals = Py_None;
237
238 if (!PyArg_UnpackTuple(args, "eval",
239 1, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300240 &source, &globals, &locals)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300241 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300242 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300243 return_value = builtin_eval_impl(module, source, globals, locals);
244
245exit:
246 return return_value;
247}
248
249PyDoc_STRVAR(builtin_exec__doc__,
250"exec($module, source, globals=None, locals=None, /)\n"
251"--\n"
252"\n"
253"Execute the given source in the context of globals and locals.\n"
254"\n"
255"The source may be a string representing one or more Python statements\n"
256"or a code object as returned by compile().\n"
257"The globals must be a dictionary and locals can be any mapping,\n"
258"defaulting to the current globals and locals.\n"
259"If only globals is given, locals defaults to it.");
260
261#define BUILTIN_EXEC_METHODDEF \
262 {"exec", (PyCFunction)builtin_exec, METH_VARARGS, builtin_exec__doc__},
263
264static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300265builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400266 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300267
268static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300269builtin_exec(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300270{
271 PyObject *return_value = NULL;
272 PyObject *source;
273 PyObject *globals = Py_None;
274 PyObject *locals = Py_None;
275
276 if (!PyArg_UnpackTuple(args, "exec",
277 1, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300278 &source, &globals, &locals)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300279 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300280 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300281 return_value = builtin_exec_impl(module, source, globals, locals);
282
283exit:
284 return return_value;
285}
286
287PyDoc_STRVAR(builtin_globals__doc__,
288"globals($module, /)\n"
289"--\n"
290"\n"
291"Return the dictionary containing the current scope\'s global variables.\n"
292"\n"
293"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
294"global scope and vice-versa.");
295
296#define BUILTIN_GLOBALS_METHODDEF \
297 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
298
299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300300builtin_globals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300301
302static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300303builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300304{
305 return builtin_globals_impl(module);
306}
307
308PyDoc_STRVAR(builtin_hasattr__doc__,
309"hasattr($module, obj, name, /)\n"
310"--\n"
311"\n"
312"Return whether the object has an attribute with the given name.\n"
313"\n"
314"This is done by calling getattr(obj, name) and catching AttributeError.");
315
316#define BUILTIN_HASATTR_METHODDEF \
317 {"hasattr", (PyCFunction)builtin_hasattr, METH_VARARGS, builtin_hasattr__doc__},
318
319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300320builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300321
322static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300323builtin_hasattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300324{
325 PyObject *return_value = NULL;
326 PyObject *obj;
327 PyObject *name;
328
329 if (!PyArg_UnpackTuple(args, "hasattr",
330 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300331 &obj, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300332 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300333 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300334 return_value = builtin_hasattr_impl(module, obj, name);
335
336exit:
337 return return_value;
338}
339
340PyDoc_STRVAR(builtin_id__doc__,
341"id($module, obj, /)\n"
342"--\n"
343"\n"
344"Return the identity of an object.\n"
345"\n"
346"This is guaranteed to be unique among simultaneously existing objects.\n"
347"(CPython uses the object\'s memory address.)");
348
349#define BUILTIN_ID_METHODDEF \
350 {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
351
352PyDoc_STRVAR(builtin_setattr__doc__,
353"setattr($module, obj, name, value, /)\n"
354"--\n"
355"\n"
356"Sets the named attribute on the given object to the specified value.\n"
357"\n"
358"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
359
360#define BUILTIN_SETATTR_METHODDEF \
361 {"setattr", (PyCFunction)builtin_setattr, METH_VARARGS, builtin_setattr__doc__},
362
363static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300364builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
Larry Hastings89964c42015-04-14 18:07:59 -0400365 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300366
367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300368builtin_setattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300369{
370 PyObject *return_value = NULL;
371 PyObject *obj;
372 PyObject *name;
373 PyObject *value;
374
375 if (!PyArg_UnpackTuple(args, "setattr",
376 3, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300377 &obj, &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300378 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300379 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300380 return_value = builtin_setattr_impl(module, obj, name, value);
381
382exit:
383 return return_value;
384}
385
386PyDoc_STRVAR(builtin_delattr__doc__,
387"delattr($module, obj, name, /)\n"
388"--\n"
389"\n"
390"Deletes the named attribute from the given object.\n"
391"\n"
392"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
393
394#define BUILTIN_DELATTR_METHODDEF \
395 {"delattr", (PyCFunction)builtin_delattr, METH_VARARGS, builtin_delattr__doc__},
396
397static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300398builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300399
400static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300401builtin_delattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300402{
403 PyObject *return_value = NULL;
404 PyObject *obj;
405 PyObject *name;
406
407 if (!PyArg_UnpackTuple(args, "delattr",
408 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300409 &obj, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300410 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300411 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300412 return_value = builtin_delattr_impl(module, obj, name);
413
414exit:
415 return return_value;
416}
417
418PyDoc_STRVAR(builtin_hash__doc__,
419"hash($module, obj, /)\n"
420"--\n"
421"\n"
422"Return the hash value for the given object.\n"
423"\n"
424"Two objects that compare equal must also have the same hash value, but the\n"
425"reverse is not necessarily true.");
426
427#define BUILTIN_HASH_METHODDEF \
428 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
429
430PyDoc_STRVAR(builtin_hex__doc__,
431"hex($module, number, /)\n"
432"--\n"
433"\n"
434"Return the hexadecimal representation of an integer.\n"
435"\n"
436" >>> hex(12648430)\n"
437" \'0xc0ffee\'");
438
439#define BUILTIN_HEX_METHODDEF \
440 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
441
442PyDoc_STRVAR(builtin_len__doc__,
443"len($module, obj, /)\n"
444"--\n"
445"\n"
446"Return the number of items in a container.");
447
448#define BUILTIN_LEN_METHODDEF \
449 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
450
451PyDoc_STRVAR(builtin_locals__doc__,
452"locals($module, /)\n"
453"--\n"
454"\n"
455"Return a dictionary containing the current scope\'s local variables.\n"
456"\n"
457"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
458"the local scope and vice-versa is *implementation dependent* and not\n"
459"covered by any backwards compatibility guarantees.");
460
461#define BUILTIN_LOCALS_METHODDEF \
462 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
463
464static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300465builtin_locals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300466
467static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300468builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300469{
470 return builtin_locals_impl(module);
471}
472
473PyDoc_STRVAR(builtin_oct__doc__,
474"oct($module, number, /)\n"
475"--\n"
476"\n"
477"Return the octal representation of an integer.\n"
478"\n"
479" >>> oct(342391)\n"
480" \'0o1234567\'");
481
482#define BUILTIN_OCT_METHODDEF \
483 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
484
485PyDoc_STRVAR(builtin_ord__doc__,
486"ord($module, c, /)\n"
487"--\n"
488"\n"
489"Return the Unicode code point for a one-character string.");
490
491#define BUILTIN_ORD_METHODDEF \
492 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
493
494PyDoc_STRVAR(builtin_pow__doc__,
495"pow($module, x, y, z=None, /)\n"
496"--\n"
497"\n"
498"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
499"\n"
500"Some types, such as ints, are able to use a more efficient algorithm when\n"
501"invoked using the three argument form.");
502
503#define BUILTIN_POW_METHODDEF \
504 {"pow", (PyCFunction)builtin_pow, METH_VARARGS, builtin_pow__doc__},
505
506static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300507builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300508
509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300510builtin_pow(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511{
512 PyObject *return_value = NULL;
513 PyObject *x;
514 PyObject *y;
515 PyObject *z = Py_None;
516
517 if (!PyArg_UnpackTuple(args, "pow",
518 2, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300519 &x, &y, &z)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300520 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300521 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300522 return_value = builtin_pow_impl(module, x, y, z);
523
524exit:
525 return return_value;
526}
527
528PyDoc_STRVAR(builtin_input__doc__,
529"input($module, prompt=None, /)\n"
530"--\n"
531"\n"
532"Read a string from standard input. The trailing newline is stripped.\n"
533"\n"
534"The prompt string, if given, is printed to standard output without a\n"
535"trailing newline before reading input.\n"
536"\n"
537"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
538"On *nix systems, readline is used if available.");
539
540#define BUILTIN_INPUT_METHODDEF \
541 {"input", (PyCFunction)builtin_input, METH_VARARGS, builtin_input__doc__},
542
543static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300544builtin_input_impl(PyObject *module, PyObject *prompt);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300545
546static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300547builtin_input(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548{
549 PyObject *return_value = NULL;
550 PyObject *prompt = NULL;
551
552 if (!PyArg_UnpackTuple(args, "input",
553 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300554 &prompt)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300555 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300556 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300557 return_value = builtin_input_impl(module, prompt);
558
559exit:
560 return return_value;
561}
562
563PyDoc_STRVAR(builtin_repr__doc__,
564"repr($module, obj, /)\n"
565"--\n"
566"\n"
567"Return the canonical string representation of the object.\n"
568"\n"
569"For many object types, including most builtins, eval(repr(obj)) == obj.");
570
571#define BUILTIN_REPR_METHODDEF \
572 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
573
574PyDoc_STRVAR(builtin_sum__doc__,
575"sum($module, iterable, start=0, /)\n"
576"--\n"
577"\n"
578"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
579"\n"
580"When the iterable is empty, return the start value.\n"
581"This function is intended specifically for use with numeric values and may\n"
582"reject non-numeric types.");
583
584#define BUILTIN_SUM_METHODDEF \
585 {"sum", (PyCFunction)builtin_sum, METH_VARARGS, builtin_sum__doc__},
586
587static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300588builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300589
590static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300591builtin_sum(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300592{
593 PyObject *return_value = NULL;
594 PyObject *iterable;
595 PyObject *start = NULL;
596
597 if (!PyArg_UnpackTuple(args, "sum",
598 1, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300599 &iterable, &start)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300600 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300601 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300602 return_value = builtin_sum_impl(module, iterable, start);
603
604exit:
605 return return_value;
606}
607
608PyDoc_STRVAR(builtin_isinstance__doc__,
609"isinstance($module, obj, class_or_tuple, /)\n"
610"--\n"
611"\n"
612"Return whether an object is an instance of a class or of a subclass thereof.\n"
613"\n"
614"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
615"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
616"or ...`` etc.");
617
618#define BUILTIN_ISINSTANCE_METHODDEF \
619 {"isinstance", (PyCFunction)builtin_isinstance, METH_VARARGS, builtin_isinstance__doc__},
620
621static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300622builtin_isinstance_impl(PyObject *module, PyObject *obj,
Larry Hastings89964c42015-04-14 18:07:59 -0400623 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300624
625static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300626builtin_isinstance(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300627{
628 PyObject *return_value = NULL;
629 PyObject *obj;
630 PyObject *class_or_tuple;
631
632 if (!PyArg_UnpackTuple(args, "isinstance",
633 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300634 &obj, &class_or_tuple)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300635 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300636 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300637 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
638
639exit:
640 return return_value;
641}
642
643PyDoc_STRVAR(builtin_issubclass__doc__,
644"issubclass($module, cls, class_or_tuple, /)\n"
645"--\n"
646"\n"
647"Return whether \'cls\' is a derived from another class or is the same class.\n"
648"\n"
649"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
650"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
651"or ...`` etc.");
652
653#define BUILTIN_ISSUBCLASS_METHODDEF \
654 {"issubclass", (PyCFunction)builtin_issubclass, METH_VARARGS, builtin_issubclass__doc__},
655
656static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300657builtin_issubclass_impl(PyObject *module, PyObject *cls,
Larry Hastings89964c42015-04-14 18:07:59 -0400658 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300659
660static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300661builtin_issubclass(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300662{
663 PyObject *return_value = NULL;
664 PyObject *cls;
665 PyObject *class_or_tuple;
666
667 if (!PyArg_UnpackTuple(args, "issubclass",
668 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300669 &cls, &class_or_tuple)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300670 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300671 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300672 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
673
674exit:
675 return return_value;
676}
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300677/*[clinic end generated code: output=790cb3d26531dfda input=a9049054013a1b77]*/