blob: 6df3ef583975558d3bf3a635a9c0fbff8059a53c [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 *
Larry Hastings89964c42015-04-14 18:07:59 -040086builtin_format_impl(PyModuleDef *module, PyObject *value,
87 PyObject *format_spec);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030088
89static PyObject *
90builtin_format(PyModuleDef *module, PyObject *args)
91{
92 PyObject *return_value = NULL;
93 PyObject *value;
94 PyObject *format_spec = NULL;
95
Serhiy Storchaka247789c2015-04-24 00:40:51 +030096 if (!PyArg_ParseTuple(args, "O|U:format",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030097 &value, &format_spec)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030098 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030099 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300100 return_value = builtin_format_impl(module, value, format_spec);
101
102exit:
103 return return_value;
104}
105
106PyDoc_STRVAR(builtin_chr__doc__,
107"chr($module, i, /)\n"
108"--\n"
109"\n"
110"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
111
112#define BUILTIN_CHR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300113 {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300114
115static PyObject *
116builtin_chr_impl(PyModuleDef *module, int i);
117
118static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300119builtin_chr(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300120{
121 PyObject *return_value = NULL;
122 int i;
123
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300124 if (!PyArg_Parse(arg, "i:chr", &i)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300127 return_value = builtin_chr_impl(module, i);
128
129exit:
130 return return_value;
131}
132
133PyDoc_STRVAR(builtin_compile__doc__,
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300134"compile($module, /, source, filename, mode, flags=0,\n"
135" dont_inherit=False, optimize=-1)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300136"--\n"
137"\n"
138"Compile source into a code object that can be executed by exec() or eval().\n"
139"\n"
140"The source code may represent a Python module, statement or expression.\n"
141"The filename will be used for run-time error messages.\n"
142"The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
143"single (interactive) statement, or \'eval\' to compile an expression.\n"
144"The flags argument, if present, controls which future statements influence\n"
145"the compilation of the code.\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300146"The dont_inherit argument, if true, stops the compilation inheriting\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300147"the effects of any future statements in effect in the code calling\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300148"compile; if absent or false these statements do influence the compilation,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300149"in addition to any features explicitly specified.");
150
151#define BUILTIN_COMPILE_METHODDEF \
152 {"compile", (PyCFunction)builtin_compile, METH_VARARGS|METH_KEYWORDS, builtin_compile__doc__},
153
154static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400155builtin_compile_impl(PyModuleDef *module, PyObject *source,
156 PyObject *filename, const char *mode, int flags,
157 int dont_inherit, int optimize);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300158
159static PyObject *
160builtin_compile(PyModuleDef *module, PyObject *args, PyObject *kwargs)
161{
162 PyObject *return_value = NULL;
163 static char *_keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL};
164 PyObject *source;
165 PyObject *filename;
166 const char *mode;
167 int flags = 0;
168 int dont_inherit = 0;
169 int optimize = -1;
170
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300171 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO&s|iii:compile", _keywords,
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 *
191builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y);
192
193static PyObject *
194builtin_divmod(PyModuleDef *module, PyObject *args)
195{
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 *
Larry Hastings89964c42015-04-14 18:07:59 -0400227builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals,
228 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300229
230static PyObject *
231builtin_eval(PyModuleDef *module, PyObject *args)
232{
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 *
Larry Hastings89964c42015-04-14 18:07:59 -0400265builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals,
266 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300267
268static PyObject *
269builtin_exec(PyModuleDef *module, PyObject *args)
270{
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 *
300builtin_globals_impl(PyModuleDef *module);
301
302static PyObject *
303builtin_globals(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
304{
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 *
320builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name);
321
322static PyObject *
323builtin_hasattr(PyModuleDef *module, PyObject *args)
324{
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 *
Larry Hastings89964c42015-04-14 18:07:59 -0400364builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name,
365 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300366
367static PyObject *
368builtin_setattr(PyModuleDef *module, PyObject *args)
369{
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 *
398builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name);
399
400static PyObject *
401builtin_delattr(PyModuleDef *module, PyObject *args)
402{
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 *
465builtin_locals_impl(PyModuleDef *module);
466
467static PyObject *
468builtin_locals(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
469{
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 *
507builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z);
508
509static PyObject *
510builtin_pow(PyModuleDef *module, PyObject *args)
511{
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 *
544builtin_input_impl(PyModuleDef *module, PyObject *prompt);
545
546static PyObject *
547builtin_input(PyModuleDef *module, PyObject *args)
548{
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 *
588builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start);
589
590static PyObject *
591builtin_sum(PyModuleDef *module, PyObject *args)
592{
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 *
Larry Hastings89964c42015-04-14 18:07:59 -0400622builtin_isinstance_impl(PyModuleDef *module, PyObject *obj,
623 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300624
625static PyObject *
626builtin_isinstance(PyModuleDef *module, PyObject *args)
627{
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 *
Larry Hastings89964c42015-04-14 18:07:59 -0400657builtin_issubclass_impl(PyModuleDef *module, PyObject *cls,
658 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300659
660static PyObject *
661builtin_issubclass(PyModuleDef *module, PyObject *args)
662{
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 Storchaka5dee6552016-06-09 16:16:06 +0300677/*[clinic end generated code: output=940f25126caf8166 input=a9049054013a1b77]*/