blob: 4e2b1f1fe8105edf9d1e145b3af63dcaed24645c [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 Storchaka1009bf12015-04-03 23:53:51 +030096 &value, &format_spec))
97 goto exit;
98 return_value = builtin_format_impl(module, value, format_spec);
99
100exit:
101 return return_value;
102}
103
104PyDoc_STRVAR(builtin_chr__doc__,
105"chr($module, i, /)\n"
106"--\n"
107"\n"
108"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
109
110#define BUILTIN_CHR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300111 {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300112
113static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300114builtin_chr_impl(PyObject *module, int i);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300115
116static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300117builtin_chr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300118{
119 PyObject *return_value = NULL;
120 int i;
121
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300122 if (!PyArg_Parse(arg, "i:chr", &i))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300123 goto exit;
124 return_value = builtin_chr_impl(module, i);
125
126exit:
127 return return_value;
128}
129
130PyDoc_STRVAR(builtin_compile__doc__,
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300131"compile($module, /, source, filename, mode, flags=0,\n"
132" dont_inherit=False, optimize=-1)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300133"--\n"
134"\n"
135"Compile source into a code object that can be executed by exec() or eval().\n"
136"\n"
137"The source code may represent a Python module, statement or expression.\n"
138"The filename will be used for run-time error messages.\n"
139"The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
140"single (interactive) statement, or \'eval\' to compile an expression.\n"
141"The flags argument, if present, controls which future statements influence\n"
142"the compilation of the code.\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300143"The dont_inherit argument, if true, stops the compilation inheriting\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300144"the effects of any future statements in effect in the code calling\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300145"compile; if absent or false these statements do influence the compilation,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300146"in addition to any features explicitly specified.");
147
148#define BUILTIN_COMPILE_METHODDEF \
149 {"compile", (PyCFunction)builtin_compile, METH_VARARGS|METH_KEYWORDS, builtin_compile__doc__},
150
151static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300152builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
153 const char *mode, int flags, int dont_inherit,
154 int optimize);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300155
156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300157builtin_compile(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300158{
159 PyObject *return_value = NULL;
160 static char *_keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL};
161 PyObject *source;
162 PyObject *filename;
163 const char *mode;
164 int flags = 0;
165 int dont_inherit = 0;
166 int optimize = -1;
167
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300168 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO&s|iii:compile", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300169 &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize))
170 goto exit;
171 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize);
172
173exit:
174 return return_value;
175}
176
177PyDoc_STRVAR(builtin_divmod__doc__,
178"divmod($module, x, y, /)\n"
179"--\n"
180"\n"
Serhiy Storchakadf071732016-05-01 20:33:24 +0300181"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300182
183#define BUILTIN_DIVMOD_METHODDEF \
184 {"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__},
185
186static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300187builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300188
189static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300190builtin_divmod(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300191{
192 PyObject *return_value = NULL;
193 PyObject *x;
194 PyObject *y;
195
196 if (!PyArg_UnpackTuple(args, "divmod",
197 2, 2,
198 &x, &y))
199 goto exit;
200 return_value = builtin_divmod_impl(module, x, y);
201
202exit:
203 return return_value;
204}
205
206PyDoc_STRVAR(builtin_eval__doc__,
207"eval($module, source, globals=None, locals=None, /)\n"
208"--\n"
209"\n"
210"Evaluate the given source in the context of globals and locals.\n"
211"\n"
212"The source may be a string representing a Python expression\n"
213"or a code object as returned by compile().\n"
214"The globals must be a dictionary and locals can be any mapping,\n"
215"defaulting to the current globals and locals.\n"
216"If only globals is given, locals defaults to it.");
217
218#define BUILTIN_EVAL_METHODDEF \
219 {"eval", (PyCFunction)builtin_eval, METH_VARARGS, builtin_eval__doc__},
220
221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300222builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400223 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300224
225static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300226builtin_eval(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300227{
228 PyObject *return_value = NULL;
229 PyObject *source;
230 PyObject *globals = Py_None;
231 PyObject *locals = Py_None;
232
233 if (!PyArg_UnpackTuple(args, "eval",
234 1, 3,
235 &source, &globals, &locals))
236 goto exit;
237 return_value = builtin_eval_impl(module, source, globals, locals);
238
239exit:
240 return return_value;
241}
242
243PyDoc_STRVAR(builtin_exec__doc__,
244"exec($module, source, globals=None, locals=None, /)\n"
245"--\n"
246"\n"
247"Execute the given source in the context of globals and locals.\n"
248"\n"
249"The source may be a string representing one or more Python statements\n"
250"or a code object as returned by compile().\n"
251"The globals must be a dictionary and locals can be any mapping,\n"
252"defaulting to the current globals and locals.\n"
253"If only globals is given, locals defaults to it.");
254
255#define BUILTIN_EXEC_METHODDEF \
256 {"exec", (PyCFunction)builtin_exec, METH_VARARGS, builtin_exec__doc__},
257
258static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300259builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400260 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300261
262static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300263builtin_exec(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300264{
265 PyObject *return_value = NULL;
266 PyObject *source;
267 PyObject *globals = Py_None;
268 PyObject *locals = Py_None;
269
270 if (!PyArg_UnpackTuple(args, "exec",
271 1, 3,
272 &source, &globals, &locals))
273 goto exit;
274 return_value = builtin_exec_impl(module, source, globals, locals);
275
276exit:
277 return return_value;
278}
279
280PyDoc_STRVAR(builtin_globals__doc__,
281"globals($module, /)\n"
282"--\n"
283"\n"
284"Return the dictionary containing the current scope\'s global variables.\n"
285"\n"
286"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
287"global scope and vice-versa.");
288
289#define BUILTIN_GLOBALS_METHODDEF \
290 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
291
292static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300293builtin_globals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300294
295static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300296builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300297{
298 return builtin_globals_impl(module);
299}
300
301PyDoc_STRVAR(builtin_hasattr__doc__,
302"hasattr($module, obj, name, /)\n"
303"--\n"
304"\n"
305"Return whether the object has an attribute with the given name.\n"
306"\n"
307"This is done by calling getattr(obj, name) and catching AttributeError.");
308
309#define BUILTIN_HASATTR_METHODDEF \
310 {"hasattr", (PyCFunction)builtin_hasattr, METH_VARARGS, builtin_hasattr__doc__},
311
312static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300313builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300314
315static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300316builtin_hasattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300317{
318 PyObject *return_value = NULL;
319 PyObject *obj;
320 PyObject *name;
321
322 if (!PyArg_UnpackTuple(args, "hasattr",
323 2, 2,
324 &obj, &name))
325 goto exit;
326 return_value = builtin_hasattr_impl(module, obj, name);
327
328exit:
329 return return_value;
330}
331
332PyDoc_STRVAR(builtin_id__doc__,
333"id($module, obj, /)\n"
334"--\n"
335"\n"
336"Return the identity of an object.\n"
337"\n"
338"This is guaranteed to be unique among simultaneously existing objects.\n"
339"(CPython uses the object\'s memory address.)");
340
341#define BUILTIN_ID_METHODDEF \
342 {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
343
344PyDoc_STRVAR(builtin_setattr__doc__,
345"setattr($module, obj, name, value, /)\n"
346"--\n"
347"\n"
348"Sets the named attribute on the given object to the specified value.\n"
349"\n"
350"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
351
352#define BUILTIN_SETATTR_METHODDEF \
353 {"setattr", (PyCFunction)builtin_setattr, METH_VARARGS, builtin_setattr__doc__},
354
355static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300356builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
Larry Hastings89964c42015-04-14 18:07:59 -0400357 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300358
359static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300360builtin_setattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300361{
362 PyObject *return_value = NULL;
363 PyObject *obj;
364 PyObject *name;
365 PyObject *value;
366
367 if (!PyArg_UnpackTuple(args, "setattr",
368 3, 3,
369 &obj, &name, &value))
370 goto exit;
371 return_value = builtin_setattr_impl(module, obj, name, value);
372
373exit:
374 return return_value;
375}
376
377PyDoc_STRVAR(builtin_delattr__doc__,
378"delattr($module, obj, name, /)\n"
379"--\n"
380"\n"
381"Deletes the named attribute from the given object.\n"
382"\n"
383"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
384
385#define BUILTIN_DELATTR_METHODDEF \
386 {"delattr", (PyCFunction)builtin_delattr, METH_VARARGS, builtin_delattr__doc__},
387
388static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300389builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300390
391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300392builtin_delattr(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300393{
394 PyObject *return_value = NULL;
395 PyObject *obj;
396 PyObject *name;
397
398 if (!PyArg_UnpackTuple(args, "delattr",
399 2, 2,
400 &obj, &name))
401 goto exit;
402 return_value = builtin_delattr_impl(module, obj, name);
403
404exit:
405 return return_value;
406}
407
408PyDoc_STRVAR(builtin_hash__doc__,
409"hash($module, obj, /)\n"
410"--\n"
411"\n"
412"Return the hash value for the given object.\n"
413"\n"
414"Two objects that compare equal must also have the same hash value, but the\n"
415"reverse is not necessarily true.");
416
417#define BUILTIN_HASH_METHODDEF \
418 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
419
420PyDoc_STRVAR(builtin_hex__doc__,
421"hex($module, number, /)\n"
422"--\n"
423"\n"
424"Return the hexadecimal representation of an integer.\n"
425"\n"
426" >>> hex(12648430)\n"
427" \'0xc0ffee\'");
428
429#define BUILTIN_HEX_METHODDEF \
430 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
431
432PyDoc_STRVAR(builtin_len__doc__,
433"len($module, obj, /)\n"
434"--\n"
435"\n"
436"Return the number of items in a container.");
437
438#define BUILTIN_LEN_METHODDEF \
439 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
440
441PyDoc_STRVAR(builtin_locals__doc__,
442"locals($module, /)\n"
443"--\n"
444"\n"
445"Return a dictionary containing the current scope\'s local variables.\n"
446"\n"
447"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
448"the local scope and vice-versa is *implementation dependent* and not\n"
449"covered by any backwards compatibility guarantees.");
450
451#define BUILTIN_LOCALS_METHODDEF \
452 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
453
454static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300455builtin_locals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300456
457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300458builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300459{
460 return builtin_locals_impl(module);
461}
462
463PyDoc_STRVAR(builtin_oct__doc__,
464"oct($module, number, /)\n"
465"--\n"
466"\n"
467"Return the octal representation of an integer.\n"
468"\n"
469" >>> oct(342391)\n"
470" \'0o1234567\'");
471
472#define BUILTIN_OCT_METHODDEF \
473 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
474
475PyDoc_STRVAR(builtin_ord__doc__,
476"ord($module, c, /)\n"
477"--\n"
478"\n"
479"Return the Unicode code point for a one-character string.");
480
481#define BUILTIN_ORD_METHODDEF \
482 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
483
484PyDoc_STRVAR(builtin_pow__doc__,
485"pow($module, x, y, z=None, /)\n"
486"--\n"
487"\n"
488"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
489"\n"
490"Some types, such as ints, are able to use a more efficient algorithm when\n"
491"invoked using the three argument form.");
492
493#define BUILTIN_POW_METHODDEF \
494 {"pow", (PyCFunction)builtin_pow, METH_VARARGS, builtin_pow__doc__},
495
496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300497builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300498
499static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300500builtin_pow(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300501{
502 PyObject *return_value = NULL;
503 PyObject *x;
504 PyObject *y;
505 PyObject *z = Py_None;
506
507 if (!PyArg_UnpackTuple(args, "pow",
508 2, 3,
509 &x, &y, &z))
510 goto exit;
511 return_value = builtin_pow_impl(module, x, y, z);
512
513exit:
514 return return_value;
515}
516
517PyDoc_STRVAR(builtin_input__doc__,
518"input($module, prompt=None, /)\n"
519"--\n"
520"\n"
521"Read a string from standard input. The trailing newline is stripped.\n"
522"\n"
523"The prompt string, if given, is printed to standard output without a\n"
524"trailing newline before reading input.\n"
525"\n"
526"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
527"On *nix systems, readline is used if available.");
528
529#define BUILTIN_INPUT_METHODDEF \
530 {"input", (PyCFunction)builtin_input, METH_VARARGS, builtin_input__doc__},
531
532static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300533builtin_input_impl(PyObject *module, PyObject *prompt);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300534
535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300536builtin_input(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300537{
538 PyObject *return_value = NULL;
539 PyObject *prompt = NULL;
540
541 if (!PyArg_UnpackTuple(args, "input",
542 0, 1,
543 &prompt))
544 goto exit;
545 return_value = builtin_input_impl(module, prompt);
546
547exit:
548 return return_value;
549}
550
551PyDoc_STRVAR(builtin_repr__doc__,
552"repr($module, obj, /)\n"
553"--\n"
554"\n"
555"Return the canonical string representation of the object.\n"
556"\n"
557"For many object types, including most builtins, eval(repr(obj)) == obj.");
558
559#define BUILTIN_REPR_METHODDEF \
560 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
561
562PyDoc_STRVAR(builtin_sum__doc__,
563"sum($module, iterable, start=0, /)\n"
564"--\n"
565"\n"
566"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
567"\n"
568"When the iterable is empty, return the start value.\n"
569"This function is intended specifically for use with numeric values and may\n"
570"reject non-numeric types.");
571
572#define BUILTIN_SUM_METHODDEF \
573 {"sum", (PyCFunction)builtin_sum, METH_VARARGS, builtin_sum__doc__},
574
575static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300576builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300577
578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300579builtin_sum(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300580{
581 PyObject *return_value = NULL;
582 PyObject *iterable;
583 PyObject *start = NULL;
584
585 if (!PyArg_UnpackTuple(args, "sum",
586 1, 2,
587 &iterable, &start))
588 goto exit;
589 return_value = builtin_sum_impl(module, iterable, start);
590
591exit:
592 return return_value;
593}
594
595PyDoc_STRVAR(builtin_isinstance__doc__,
596"isinstance($module, obj, class_or_tuple, /)\n"
597"--\n"
598"\n"
599"Return whether an object is an instance of a class or of a subclass thereof.\n"
600"\n"
601"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
602"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
603"or ...`` etc.");
604
605#define BUILTIN_ISINSTANCE_METHODDEF \
606 {"isinstance", (PyCFunction)builtin_isinstance, METH_VARARGS, builtin_isinstance__doc__},
607
608static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300609builtin_isinstance_impl(PyObject *module, PyObject *obj,
Larry Hastings89964c42015-04-14 18:07:59 -0400610 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300611
612static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300613builtin_isinstance(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300614{
615 PyObject *return_value = NULL;
616 PyObject *obj;
617 PyObject *class_or_tuple;
618
619 if (!PyArg_UnpackTuple(args, "isinstance",
620 2, 2,
621 &obj, &class_or_tuple))
622 goto exit;
623 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
624
625exit:
626 return return_value;
627}
628
629PyDoc_STRVAR(builtin_issubclass__doc__,
630"issubclass($module, cls, class_or_tuple, /)\n"
631"--\n"
632"\n"
633"Return whether \'cls\' is a derived from another class or is the same class.\n"
634"\n"
635"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
636"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
637"or ...`` etc.");
638
639#define BUILTIN_ISSUBCLASS_METHODDEF \
640 {"issubclass", (PyCFunction)builtin_issubclass, METH_VARARGS, builtin_issubclass__doc__},
641
642static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300643builtin_issubclass_impl(PyObject *module, PyObject *cls,
Larry Hastings89964c42015-04-14 18:07:59 -0400644 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300645
646static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300647builtin_issubclass(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300648{
649 PyObject *return_value = NULL;
650 PyObject *cls;
651 PyObject *class_or_tuple;
652
653 if (!PyArg_UnpackTuple(args, "issubclass",
654 2, 2,
655 &cls, &class_or_tuple))
656 goto exit;
657 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
658
659exit:
660 return return_value;
661}
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300662/*[clinic end generated code: output=9031270b64c794b8 input=a9049054013a1b77]*/