blob: 0bd859db70f2ea93b58bab051b9f4ac63c9b95dd [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 *
86builtin_format_impl(PyModuleDef *module, PyObject *value, PyObject *format_spec);
87
88static PyObject *
89builtin_format(PyModuleDef *module, PyObject *args)
90{
91 PyObject *return_value = NULL;
92 PyObject *value;
93 PyObject *format_spec = NULL;
94
95 if (!PyArg_ParseTuple(args,
96 "O|U:format",
97 &value, &format_spec))
98 goto exit;
99 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 *
115builtin_chr_impl(PyModuleDef *module, int i);
116
117static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300118builtin_chr(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300119{
120 PyObject *return_value = NULL;
121 int i;
122
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300123 if (!PyArg_Parse(arg,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300124 "i:chr",
125 &i))
126 goto exit;
127 return_value = builtin_chr_impl(module, i);
128
129exit:
130 return return_value;
131}
132
133PyDoc_STRVAR(builtin_compile__doc__,
134"compile($module, /, source, filename, mode, flags=0, dont_inherit=0,\n"
135" optimize=-1)\n"
136"--\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"
146"The dont_inherit argument, if non-zero, stops the compilation inheriting\n"
147"the effects of any future statements in effect in the code calling\n"
148"compile; if absent or zero these statements do influence the compilation,\n"
149"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 *
155builtin_compile_impl(PyModuleDef *module, PyObject *source, PyObject *filename, const char *mode, int flags, int dont_inherit, int optimize);
156
157static PyObject *
158builtin_compile(PyModuleDef *module, PyObject *args, PyObject *kwargs)
159{
160 PyObject *return_value = NULL;
161 static char *_keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL};
162 PyObject *source;
163 PyObject *filename;
164 const char *mode;
165 int flags = 0;
166 int dont_inherit = 0;
167 int optimize = -1;
168
169 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
170 "OO&s|iii:compile", _keywords,
171 &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize))
172 goto exit;
173 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize);
174
175exit:
176 return return_value;
177}
178
179PyDoc_STRVAR(builtin_divmod__doc__,
180"divmod($module, x, y, /)\n"
181"--\n"
182"\n"
183"Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.");
184
185#define BUILTIN_DIVMOD_METHODDEF \
186 {"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__},
187
188static PyObject *
189builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y);
190
191static PyObject *
192builtin_divmod(PyModuleDef *module, PyObject *args)
193{
194 PyObject *return_value = NULL;
195 PyObject *x;
196 PyObject *y;
197
198 if (!PyArg_UnpackTuple(args, "divmod",
199 2, 2,
200 &x, &y))
201 goto exit;
202 return_value = builtin_divmod_impl(module, x, y);
203
204exit:
205 return return_value;
206}
207
208PyDoc_STRVAR(builtin_eval__doc__,
209"eval($module, source, globals=None, locals=None, /)\n"
210"--\n"
211"\n"
212"Evaluate the given source in the context of globals and locals.\n"
213"\n"
214"The source may be a string representing a Python expression\n"
215"or a code object as returned by compile().\n"
216"The globals must be a dictionary and locals can be any mapping,\n"
217"defaulting to the current globals and locals.\n"
218"If only globals is given, locals defaults to it.");
219
220#define BUILTIN_EVAL_METHODDEF \
221 {"eval", (PyCFunction)builtin_eval, METH_VARARGS, builtin_eval__doc__},
222
223static PyObject *
224builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals);
225
226static PyObject *
227builtin_eval(PyModuleDef *module, PyObject *args)
228{
229 PyObject *return_value = NULL;
230 PyObject *source;
231 PyObject *globals = Py_None;
232 PyObject *locals = Py_None;
233
234 if (!PyArg_UnpackTuple(args, "eval",
235 1, 3,
236 &source, &globals, &locals))
237 goto exit;
238 return_value = builtin_eval_impl(module, source, globals, locals);
239
240exit:
241 return return_value;
242}
243
244PyDoc_STRVAR(builtin_exec__doc__,
245"exec($module, source, globals=None, locals=None, /)\n"
246"--\n"
247"\n"
248"Execute the given source in the context of globals and locals.\n"
249"\n"
250"The source may be a string representing one or more Python statements\n"
251"or a code object as returned by compile().\n"
252"The globals must be a dictionary and locals can be any mapping,\n"
253"defaulting to the current globals and locals.\n"
254"If only globals is given, locals defaults to it.");
255
256#define BUILTIN_EXEC_METHODDEF \
257 {"exec", (PyCFunction)builtin_exec, METH_VARARGS, builtin_exec__doc__},
258
259static PyObject *
260builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, PyObject *locals);
261
262static PyObject *
263builtin_exec(PyModuleDef *module, PyObject *args)
264{
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 *
293builtin_globals_impl(PyModuleDef *module);
294
295static PyObject *
296builtin_globals(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
297{
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 *
313builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name);
314
315static PyObject *
316builtin_hasattr(PyModuleDef *module, PyObject *args)
317{
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 *
356builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, PyObject *value);
357
358static PyObject *
359builtin_setattr(PyModuleDef *module, PyObject *args)
360{
361 PyObject *return_value = NULL;
362 PyObject *obj;
363 PyObject *name;
364 PyObject *value;
365
366 if (!PyArg_UnpackTuple(args, "setattr",
367 3, 3,
368 &obj, &name, &value))
369 goto exit;
370 return_value = builtin_setattr_impl(module, obj, name, value);
371
372exit:
373 return return_value;
374}
375
376PyDoc_STRVAR(builtin_delattr__doc__,
377"delattr($module, obj, name, /)\n"
378"--\n"
379"\n"
380"Deletes the named attribute from the given object.\n"
381"\n"
382"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
383
384#define BUILTIN_DELATTR_METHODDEF \
385 {"delattr", (PyCFunction)builtin_delattr, METH_VARARGS, builtin_delattr__doc__},
386
387static PyObject *
388builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name);
389
390static PyObject *
391builtin_delattr(PyModuleDef *module, PyObject *args)
392{
393 PyObject *return_value = NULL;
394 PyObject *obj;
395 PyObject *name;
396
397 if (!PyArg_UnpackTuple(args, "delattr",
398 2, 2,
399 &obj, &name))
400 goto exit;
401 return_value = builtin_delattr_impl(module, obj, name);
402
403exit:
404 return return_value;
405}
406
407PyDoc_STRVAR(builtin_hash__doc__,
408"hash($module, obj, /)\n"
409"--\n"
410"\n"
411"Return the hash value for the given object.\n"
412"\n"
413"Two objects that compare equal must also have the same hash value, but the\n"
414"reverse is not necessarily true.");
415
416#define BUILTIN_HASH_METHODDEF \
417 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
418
419PyDoc_STRVAR(builtin_hex__doc__,
420"hex($module, number, /)\n"
421"--\n"
422"\n"
423"Return the hexadecimal representation of an integer.\n"
424"\n"
425" >>> hex(12648430)\n"
426" \'0xc0ffee\'");
427
428#define BUILTIN_HEX_METHODDEF \
429 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
430
431PyDoc_STRVAR(builtin_len__doc__,
432"len($module, obj, /)\n"
433"--\n"
434"\n"
435"Return the number of items in a container.");
436
437#define BUILTIN_LEN_METHODDEF \
438 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
439
440PyDoc_STRVAR(builtin_locals__doc__,
441"locals($module, /)\n"
442"--\n"
443"\n"
444"Return a dictionary containing the current scope\'s local variables.\n"
445"\n"
446"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
447"the local scope and vice-versa is *implementation dependent* and not\n"
448"covered by any backwards compatibility guarantees.");
449
450#define BUILTIN_LOCALS_METHODDEF \
451 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
452
453static PyObject *
454builtin_locals_impl(PyModuleDef *module);
455
456static PyObject *
457builtin_locals(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
458{
459 return builtin_locals_impl(module);
460}
461
462PyDoc_STRVAR(builtin_oct__doc__,
463"oct($module, number, /)\n"
464"--\n"
465"\n"
466"Return the octal representation of an integer.\n"
467"\n"
468" >>> oct(342391)\n"
469" \'0o1234567\'");
470
471#define BUILTIN_OCT_METHODDEF \
472 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
473
474PyDoc_STRVAR(builtin_ord__doc__,
475"ord($module, c, /)\n"
476"--\n"
477"\n"
478"Return the Unicode code point for a one-character string.");
479
480#define BUILTIN_ORD_METHODDEF \
481 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
482
483PyDoc_STRVAR(builtin_pow__doc__,
484"pow($module, x, y, z=None, /)\n"
485"--\n"
486"\n"
487"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
488"\n"
489"Some types, such as ints, are able to use a more efficient algorithm when\n"
490"invoked using the three argument form.");
491
492#define BUILTIN_POW_METHODDEF \
493 {"pow", (PyCFunction)builtin_pow, METH_VARARGS, builtin_pow__doc__},
494
495static PyObject *
496builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z);
497
498static PyObject *
499builtin_pow(PyModuleDef *module, PyObject *args)
500{
501 PyObject *return_value = NULL;
502 PyObject *x;
503 PyObject *y;
504 PyObject *z = Py_None;
505
506 if (!PyArg_UnpackTuple(args, "pow",
507 2, 3,
508 &x, &y, &z))
509 goto exit;
510 return_value = builtin_pow_impl(module, x, y, z);
511
512exit:
513 return return_value;
514}
515
516PyDoc_STRVAR(builtin_input__doc__,
517"input($module, prompt=None, /)\n"
518"--\n"
519"\n"
520"Read a string from standard input. The trailing newline is stripped.\n"
521"\n"
522"The prompt string, if given, is printed to standard output without a\n"
523"trailing newline before reading input.\n"
524"\n"
525"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
526"On *nix systems, readline is used if available.");
527
528#define BUILTIN_INPUT_METHODDEF \
529 {"input", (PyCFunction)builtin_input, METH_VARARGS, builtin_input__doc__},
530
531static PyObject *
532builtin_input_impl(PyModuleDef *module, PyObject *prompt);
533
534static PyObject *
535builtin_input(PyModuleDef *module, PyObject *args)
536{
537 PyObject *return_value = NULL;
538 PyObject *prompt = NULL;
539
540 if (!PyArg_UnpackTuple(args, "input",
541 0, 1,
542 &prompt))
543 goto exit;
544 return_value = builtin_input_impl(module, prompt);
545
546exit:
547 return return_value;
548}
549
550PyDoc_STRVAR(builtin_repr__doc__,
551"repr($module, obj, /)\n"
552"--\n"
553"\n"
554"Return the canonical string representation of the object.\n"
555"\n"
556"For many object types, including most builtins, eval(repr(obj)) == obj.");
557
558#define BUILTIN_REPR_METHODDEF \
559 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
560
561PyDoc_STRVAR(builtin_sum__doc__,
562"sum($module, iterable, start=0, /)\n"
563"--\n"
564"\n"
565"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
566"\n"
567"When the iterable is empty, return the start value.\n"
568"This function is intended specifically for use with numeric values and may\n"
569"reject non-numeric types.");
570
571#define BUILTIN_SUM_METHODDEF \
572 {"sum", (PyCFunction)builtin_sum, METH_VARARGS, builtin_sum__doc__},
573
574static PyObject *
575builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start);
576
577static PyObject *
578builtin_sum(PyModuleDef *module, PyObject *args)
579{
580 PyObject *return_value = NULL;
581 PyObject *iterable;
582 PyObject *start = NULL;
583
584 if (!PyArg_UnpackTuple(args, "sum",
585 1, 2,
586 &iterable, &start))
587 goto exit;
588 return_value = builtin_sum_impl(module, iterable, start);
589
590exit:
591 return return_value;
592}
593
594PyDoc_STRVAR(builtin_isinstance__doc__,
595"isinstance($module, obj, class_or_tuple, /)\n"
596"--\n"
597"\n"
598"Return whether an object is an instance of a class or of a subclass thereof.\n"
599"\n"
600"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
601"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
602"or ...`` etc.");
603
604#define BUILTIN_ISINSTANCE_METHODDEF \
605 {"isinstance", (PyCFunction)builtin_isinstance, METH_VARARGS, builtin_isinstance__doc__},
606
607static PyObject *
608builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, PyObject *class_or_tuple);
609
610static PyObject *
611builtin_isinstance(PyModuleDef *module, PyObject *args)
612{
613 PyObject *return_value = NULL;
614 PyObject *obj;
615 PyObject *class_or_tuple;
616
617 if (!PyArg_UnpackTuple(args, "isinstance",
618 2, 2,
619 &obj, &class_or_tuple))
620 goto exit;
621 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
622
623exit:
624 return return_value;
625}
626
627PyDoc_STRVAR(builtin_issubclass__doc__,
628"issubclass($module, cls, class_or_tuple, /)\n"
629"--\n"
630"\n"
631"Return whether \'cls\' is a derived from another class or is the same class.\n"
632"\n"
633"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
634"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
635"or ...`` etc.");
636
637#define BUILTIN_ISSUBCLASS_METHODDEF \
638 {"issubclass", (PyCFunction)builtin_issubclass, METH_VARARGS, builtin_issubclass__doc__},
639
640static PyObject *
641builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, PyObject *class_or_tuple);
642
643static PyObject *
644builtin_issubclass(PyModuleDef *module, PyObject *args)
645{
646 PyObject *return_value = NULL;
647 PyObject *cls;
648 PyObject *class_or_tuple;
649
650 if (!PyArg_UnpackTuple(args, "issubclass",
651 2, 2,
652 &cls, &class_or_tuple))
653 goto exit;
654 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
655
656exit:
657 return return_value;
658}
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300659/*[clinic end generated code: output=12db4cde92eb11b3 input=a9049054013a1b77]*/