1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(builtin___import____doc__,
6"__import__($module, /, name, globals=None, locals=None, fromlist=(),\n"
7"           level=0)\n"
8"--\n"
9"\n"
10"Import a module.\n"
11"\n"
12"Because this function is meant for use by the Python\n"
13"interpreter and not for general use, it is better to use\n"
14"importlib.import_module() to programmatically import a module.\n"
15"\n"
16"The globals argument is only used to determine the context;\n"
17"they are not modified.  The locals argument is unused.  The fromlist\n"
18"should be a list of names to emulate ``from name import ...``, or an\n"
19"empty list to emulate ``import name``.\n"
20"When importing a module from a package, note that __import__(\'A.B\', ...)\n"
21"returns package A when fromlist is empty, but its submodule B when\n"
22"fromlist is not empty.  The level argument is used to determine whether to\n"
23"perform absolute or relative imports: 0 is absolute, while a positive number\n"
24"is the number of parent directories to search relative to the current module.");
25
26#define BUILTIN___IMPORT___METHODDEF    \
27    {"__import__", _PyCFunction_CAST(builtin___import__), METH_FASTCALL|METH_KEYWORDS, builtin___import____doc__},
28
29static PyObject *
30builtin___import___impl(PyObject *module, PyObject *name, PyObject *globals,
31                        PyObject *locals, PyObject *fromlist, int level);
32
33static PyObject *
34builtin___import__(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
35{
36    PyObject *return_value = NULL;
37    static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL};
38    static _PyArg_Parser _parser = {NULL, _keywords, "__import__", 0};
39    PyObject *argsbuf[5];
40    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
41    PyObject *name;
42    PyObject *globals = NULL;
43    PyObject *locals = NULL;
44    PyObject *fromlist = NULL;
45    int level = 0;
46
47    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf);
48    if (!args) {
49        goto exit;
50    }
51    name = args[0];
52    if (!noptargs) {
53        goto skip_optional_pos;
54    }
55    if (args[1]) {
56        globals = args[1];
57        if (!--noptargs) {
58            goto skip_optional_pos;
59        }
60    }
61    if (args[2]) {
62        locals = args[2];
63        if (!--noptargs) {
64            goto skip_optional_pos;
65        }
66    }
67    if (args[3]) {
68        fromlist = args[3];
69        if (!--noptargs) {
70            goto skip_optional_pos;
71        }
72    }
73    level = _PyLong_AsInt(args[4]);
74    if (level == -1 && PyErr_Occurred()) {
75        goto exit;
76    }
77skip_optional_pos:
78    return_value = builtin___import___impl(module, name, globals, locals, fromlist, level);
79
80exit:
81    return return_value;
82}
83
84PyDoc_STRVAR(builtin_abs__doc__,
85"abs($module, x, /)\n"
86"--\n"
87"\n"
88"Return the absolute value of the argument.");
89
90#define BUILTIN_ABS_METHODDEF    \
91    {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__},
92
93PyDoc_STRVAR(builtin_all__doc__,
94"all($module, iterable, /)\n"
95"--\n"
96"\n"
97"Return True if bool(x) is True for all values x in the iterable.\n"
98"\n"
99"If the iterable is empty, return True.");
100
101#define BUILTIN_ALL_METHODDEF    \
102    {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__},
103
104PyDoc_STRVAR(builtin_any__doc__,
105"any($module, iterable, /)\n"
106"--\n"
107"\n"
108"Return True if bool(x) is True for any x in the iterable.\n"
109"\n"
110"If the iterable is empty, return False.");
111
112#define BUILTIN_ANY_METHODDEF    \
113    {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__},
114
115PyDoc_STRVAR(builtin_ascii__doc__,
116"ascii($module, obj, /)\n"
117"--\n"
118"\n"
119"Return an ASCII-only representation of an object.\n"
120"\n"
121"As repr(), return a string containing a printable representation of an\n"
122"object, but escape the non-ASCII characters in the string returned by\n"
123"repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n"
124"to that returned by repr() in Python 2.");
125
126#define BUILTIN_ASCII_METHODDEF    \
127    {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__},
128
129PyDoc_STRVAR(builtin_bin__doc__,
130"bin($module, number, /)\n"
131"--\n"
132"\n"
133"Return the binary representation of an integer.\n"
134"\n"
135"   >>> bin(2796202)\n"
136"   \'0b1010101010101010101010\'");
137
138#define BUILTIN_BIN_METHODDEF    \
139    {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__},
140
141PyDoc_STRVAR(builtin_callable__doc__,
142"callable($module, obj, /)\n"
143"--\n"
144"\n"
145"Return whether the object is callable (i.e., some kind of function).\n"
146"\n"
147"Note that classes are callable, as are instances of classes with a\n"
148"__call__() method.");
149
150#define BUILTIN_CALLABLE_METHODDEF    \
151    {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__},
152
153PyDoc_STRVAR(builtin_format__doc__,
154"format($module, value, format_spec=\'\', /)\n"
155"--\n"
156"\n"
157"Return value.__format__(format_spec)\n"
158"\n"
159"format_spec defaults to the empty string.\n"
160"See the Format Specification Mini-Language section of help(\'FORMATTING\') for\n"
161"details.");
162
163#define BUILTIN_FORMAT_METHODDEF    \
164    {"format", _PyCFunction_CAST(builtin_format), METH_FASTCALL, builtin_format__doc__},
165
166static PyObject *
167builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec);
168
169static PyObject *
170builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
171{
172    PyObject *return_value = NULL;
173    PyObject *value;
174    PyObject *format_spec = NULL;
175
176    if (!_PyArg_CheckPositional("format", nargs, 1, 2)) {
177        goto exit;
178    }
179    value = args[0];
180    if (nargs < 2) {
181        goto skip_optional;
182    }
183    if (!PyUnicode_Check(args[1])) {
184        _PyArg_BadArgument("format", "argument 2", "str", args[1]);
185        goto exit;
186    }
187    if (PyUnicode_READY(args[1]) == -1) {
188        goto exit;
189    }
190    format_spec = args[1];
191skip_optional:
192    return_value = builtin_format_impl(module, value, format_spec);
193
194exit:
195    return return_value;
196}
197
198PyDoc_STRVAR(builtin_chr__doc__,
199"chr($module, i, /)\n"
200"--\n"
201"\n"
202"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
203
204#define BUILTIN_CHR_METHODDEF    \
205    {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
206
207static PyObject *
208builtin_chr_impl(PyObject *module, int i);
209
210static PyObject *
211builtin_chr(PyObject *module, PyObject *arg)
212{
213    PyObject *return_value = NULL;
214    int i;
215
216    i = _PyLong_AsInt(arg);
217    if (i == -1 && PyErr_Occurred()) {
218        goto exit;
219    }
220    return_value = builtin_chr_impl(module, i);
221
222exit:
223    return return_value;
224}
225
226PyDoc_STRVAR(builtin_compile__doc__,
227"compile($module, /, source, filename, mode, flags=0,\n"
228"        dont_inherit=False, optimize=-1, *, _feature_version=-1)\n"
229"--\n"
230"\n"
231"Compile source into a code object that can be executed by exec() or eval().\n"
232"\n"
233"The source code may represent a Python module, statement or expression.\n"
234"The filename will be used for run-time error messages.\n"
235"The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
236"single (interactive) statement, or \'eval\' to compile an expression.\n"
237"The flags argument, if present, controls which future statements influence\n"
238"the compilation of the code.\n"
239"The dont_inherit argument, if true, stops the compilation inheriting\n"
240"the effects of any future statements in effect in the code calling\n"
241"compile; if absent or false these statements do influence the compilation,\n"
242"in addition to any features explicitly specified.");
243
244#define BUILTIN_COMPILE_METHODDEF    \
245    {"compile", _PyCFunction_CAST(builtin_compile), METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__},
246
247static PyObject *
248builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
249                     const char *mode, int flags, int dont_inherit,
250                     int optimize, int feature_version);
251
252static PyObject *
253builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
254{
255    PyObject *return_value = NULL;
256    static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "_feature_version", NULL};
257    static _PyArg_Parser _parser = {NULL, _keywords, "compile", 0};
258    PyObject *argsbuf[7];
259    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
260    PyObject *source;
261    PyObject *filename;
262    const char *mode;
263    int flags = 0;
264    int dont_inherit = 0;
265    int optimize = -1;
266    int feature_version = -1;
267
268    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf);
269    if (!args) {
270        goto exit;
271    }
272    source = args[0];
273    if (!PyUnicode_FSDecoder(args[1], &filename)) {
274        goto exit;
275    }
276    if (!PyUnicode_Check(args[2])) {
277        _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]);
278        goto exit;
279    }
280    Py_ssize_t mode_length;
281    mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length);
282    if (mode == NULL) {
283        goto exit;
284    }
285    if (strlen(mode) != (size_t)mode_length) {
286        PyErr_SetString(PyExc_ValueError, "embedded null character");
287        goto exit;
288    }
289    if (!noptargs) {
290        goto skip_optional_pos;
291    }
292    if (args[3]) {
293        flags = _PyLong_AsInt(args[3]);
294        if (flags == -1 && PyErr_Occurred()) {
295            goto exit;
296        }
297        if (!--noptargs) {
298            goto skip_optional_pos;
299        }
300    }
301    if (args[4]) {
302        dont_inherit = _PyLong_AsInt(args[4]);
303        if (dont_inherit == -1 && PyErr_Occurred()) {
304            goto exit;
305        }
306        if (!--noptargs) {
307            goto skip_optional_pos;
308        }
309    }
310    if (args[5]) {
311        optimize = _PyLong_AsInt(args[5]);
312        if (optimize == -1 && PyErr_Occurred()) {
313            goto exit;
314        }
315        if (!--noptargs) {
316            goto skip_optional_pos;
317        }
318    }
319skip_optional_pos:
320    if (!noptargs) {
321        goto skip_optional_kwonly;
322    }
323    feature_version = _PyLong_AsInt(args[6]);
324    if (feature_version == -1 && PyErr_Occurred()) {
325        goto exit;
326    }
327skip_optional_kwonly:
328    return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version);
329
330exit:
331    return return_value;
332}
333
334PyDoc_STRVAR(builtin_divmod__doc__,
335"divmod($module, x, y, /)\n"
336"--\n"
337"\n"
338"Return the tuple (x//y, x%y).  Invariant: div*y + mod == x.");
339
340#define BUILTIN_DIVMOD_METHODDEF    \
341    {"divmod", _PyCFunction_CAST(builtin_divmod), METH_FASTCALL, builtin_divmod__doc__},
342
343static PyObject *
344builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
345
346static PyObject *
347builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
348{
349    PyObject *return_value = NULL;
350    PyObject *x;
351    PyObject *y;
352
353    if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
354        goto exit;
355    }
356    x = args[0];
357    y = args[1];
358    return_value = builtin_divmod_impl(module, x, y);
359
360exit:
361    return return_value;
362}
363
364PyDoc_STRVAR(builtin_eval__doc__,
365"eval($module, source, globals=None, locals=None, /)\n"
366"--\n"
367"\n"
368"Evaluate the given source in the context of globals and locals.\n"
369"\n"
370"The source may be a string representing a Python expression\n"
371"or a code object as returned by compile().\n"
372"The globals must be a dictionary and locals can be any mapping,\n"
373"defaulting to the current globals and locals.\n"
374"If only globals is given, locals defaults to it.");
375
376#define BUILTIN_EVAL_METHODDEF    \
377    {"eval", _PyCFunction_CAST(builtin_eval), METH_FASTCALL, builtin_eval__doc__},
378
379static PyObject *
380builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
381                  PyObject *locals);
382
383static PyObject *
384builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
385{
386    PyObject *return_value = NULL;
387    PyObject *source;
388    PyObject *globals = Py_None;
389    PyObject *locals = Py_None;
390
391    if (!_PyArg_CheckPositional("eval", nargs, 1, 3)) {
392        goto exit;
393    }
394    source = args[0];
395    if (nargs < 2) {
396        goto skip_optional;
397    }
398    globals = args[1];
399    if (nargs < 3) {
400        goto skip_optional;
401    }
402    locals = args[2];
403skip_optional:
404    return_value = builtin_eval_impl(module, source, globals, locals);
405
406exit:
407    return return_value;
408}
409
410PyDoc_STRVAR(builtin_exec__doc__,
411"exec($module, source, globals=None, locals=None, /, *, closure=None)\n"
412"--\n"
413"\n"
414"Execute the given source in the context of globals and locals.\n"
415"\n"
416"The source may be a string representing one or more Python statements\n"
417"or a code object as returned by compile().\n"
418"The globals must be a dictionary and locals can be any mapping,\n"
419"defaulting to the current globals and locals.\n"
420"If only globals is given, locals defaults to it.\n"
421"The closure must be a tuple of cellvars, and can only be used\n"
422"when source is a code object requiring exactly that many cellvars.");
423
424#define BUILTIN_EXEC_METHODDEF    \
425    {"exec", _PyCFunction_CAST(builtin_exec), METH_FASTCALL|METH_KEYWORDS, builtin_exec__doc__},
426
427static PyObject *
428builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
429                  PyObject *locals, PyObject *closure);
430
431static PyObject *
432builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
433{
434    PyObject *return_value = NULL;
435    static const char * const _keywords[] = {"", "", "", "closure", NULL};
436    static _PyArg_Parser _parser = {NULL, _keywords, "exec", 0};
437    PyObject *argsbuf[4];
438    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
439    PyObject *source;
440    PyObject *globals = Py_None;
441    PyObject *locals = Py_None;
442    PyObject *closure = NULL;
443
444    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
445    if (!args) {
446        goto exit;
447    }
448    source = args[0];
449    if (nargs < 2) {
450        goto skip_optional_posonly;
451    }
452    noptargs--;
453    globals = args[1];
454    if (nargs < 3) {
455        goto skip_optional_posonly;
456    }
457    noptargs--;
458    locals = args[2];
459skip_optional_posonly:
460    if (!noptargs) {
461        goto skip_optional_kwonly;
462    }
463    closure = args[3];
464skip_optional_kwonly:
465    return_value = builtin_exec_impl(module, source, globals, locals, closure);
466
467exit:
468    return return_value;
469}
470
471PyDoc_STRVAR(builtin_globals__doc__,
472"globals($module, /)\n"
473"--\n"
474"\n"
475"Return the dictionary containing the current scope\'s global variables.\n"
476"\n"
477"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
478"global scope and vice-versa.");
479
480#define BUILTIN_GLOBALS_METHODDEF    \
481    {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
482
483static PyObject *
484builtin_globals_impl(PyObject *module);
485
486static PyObject *
487builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
488{
489    return builtin_globals_impl(module);
490}
491
492PyDoc_STRVAR(builtin_hasattr__doc__,
493"hasattr($module, obj, name, /)\n"
494"--\n"
495"\n"
496"Return whether the object has an attribute with the given name.\n"
497"\n"
498"This is done by calling getattr(obj, name) and catching AttributeError.");
499
500#define BUILTIN_HASATTR_METHODDEF    \
501    {"hasattr", _PyCFunction_CAST(builtin_hasattr), METH_FASTCALL, builtin_hasattr__doc__},
502
503static PyObject *
504builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
505
506static PyObject *
507builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
508{
509    PyObject *return_value = NULL;
510    PyObject *obj;
511    PyObject *name;
512
513    if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
514        goto exit;
515    }
516    obj = args[0];
517    name = args[1];
518    return_value = builtin_hasattr_impl(module, obj, name);
519
520exit:
521    return return_value;
522}
523
524PyDoc_STRVAR(builtin_id__doc__,
525"id($module, obj, /)\n"
526"--\n"
527"\n"
528"Return the identity of an object.\n"
529"\n"
530"This is guaranteed to be unique among simultaneously existing objects.\n"
531"(CPython uses the object\'s memory address.)");
532
533#define BUILTIN_ID_METHODDEF    \
534    {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
535
536PyDoc_STRVAR(builtin_setattr__doc__,
537"setattr($module, obj, name, value, /)\n"
538"--\n"
539"\n"
540"Sets the named attribute on the given object to the specified value.\n"
541"\n"
542"setattr(x, \'y\', v) is equivalent to ``x.y = v``");
543
544#define BUILTIN_SETATTR_METHODDEF    \
545    {"setattr", _PyCFunction_CAST(builtin_setattr), METH_FASTCALL, builtin_setattr__doc__},
546
547static PyObject *
548builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
549                     PyObject *value);
550
551static PyObject *
552builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
553{
554    PyObject *return_value = NULL;
555    PyObject *obj;
556    PyObject *name;
557    PyObject *value;
558
559    if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) {
560        goto exit;
561    }
562    obj = args[0];
563    name = args[1];
564    value = args[2];
565    return_value = builtin_setattr_impl(module, obj, name, value);
566
567exit:
568    return return_value;
569}
570
571PyDoc_STRVAR(builtin_delattr__doc__,
572"delattr($module, obj, name, /)\n"
573"--\n"
574"\n"
575"Deletes the named attribute from the given object.\n"
576"\n"
577"delattr(x, \'y\') is equivalent to ``del x.y``");
578
579#define BUILTIN_DELATTR_METHODDEF    \
580    {"delattr", _PyCFunction_CAST(builtin_delattr), METH_FASTCALL, builtin_delattr__doc__},
581
582static PyObject *
583builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
584
585static PyObject *
586builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
587{
588    PyObject *return_value = NULL;
589    PyObject *obj;
590    PyObject *name;
591
592    if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
593        goto exit;
594    }
595    obj = args[0];
596    name = args[1];
597    return_value = builtin_delattr_impl(module, obj, name);
598
599exit:
600    return return_value;
601}
602
603PyDoc_STRVAR(builtin_hash__doc__,
604"hash($module, obj, /)\n"
605"--\n"
606"\n"
607"Return the hash value for the given object.\n"
608"\n"
609"Two objects that compare equal must also have the same hash value, but the\n"
610"reverse is not necessarily true.");
611
612#define BUILTIN_HASH_METHODDEF    \
613    {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
614
615PyDoc_STRVAR(builtin_hex__doc__,
616"hex($module, number, /)\n"
617"--\n"
618"\n"
619"Return the hexadecimal representation of an integer.\n"
620"\n"
621"   >>> hex(12648430)\n"
622"   \'0xc0ffee\'");
623
624#define BUILTIN_HEX_METHODDEF    \
625    {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
626
627PyDoc_STRVAR(builtin_aiter__doc__,
628"aiter($module, async_iterable, /)\n"
629"--\n"
630"\n"
631"Return an AsyncIterator for an AsyncIterable object.");
632
633#define BUILTIN_AITER_METHODDEF    \
634    {"aiter", (PyCFunction)builtin_aiter, METH_O, builtin_aiter__doc__},
635
636PyDoc_STRVAR(builtin_anext__doc__,
637"anext($module, aiterator, default=<unrepresentable>, /)\n"
638"--\n"
639"\n"
640"async anext(aiterator[, default])\n"
641"\n"
642"Return the next item from the async iterator.  If default is given and the async\n"
643"iterator is exhausted, it is returned instead of raising StopAsyncIteration.");
644
645#define BUILTIN_ANEXT_METHODDEF    \
646    {"anext", _PyCFunction_CAST(builtin_anext), METH_FASTCALL, builtin_anext__doc__},
647
648static PyObject *
649builtin_anext_impl(PyObject *module, PyObject *aiterator,
650                   PyObject *default_value);
651
652static PyObject *
653builtin_anext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
654{
655    PyObject *return_value = NULL;
656    PyObject *aiterator;
657    PyObject *default_value = NULL;
658
659    if (!_PyArg_CheckPositional("anext", nargs, 1, 2)) {
660        goto exit;
661    }
662    aiterator = args[0];
663    if (nargs < 2) {
664        goto skip_optional;
665    }
666    default_value = args[1];
667skip_optional:
668    return_value = builtin_anext_impl(module, aiterator, default_value);
669
670exit:
671    return return_value;
672}
673
674PyDoc_STRVAR(builtin_len__doc__,
675"len($module, obj, /)\n"
676"--\n"
677"\n"
678"Return the number of items in a container.");
679
680#define BUILTIN_LEN_METHODDEF    \
681    {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
682
683PyDoc_STRVAR(builtin_locals__doc__,
684"locals($module, /)\n"
685"--\n"
686"\n"
687"Return a dictionary containing the current scope\'s local variables.\n"
688"\n"
689"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
690"the local scope and vice-versa is *implementation dependent* and not\n"
691"covered by any backwards compatibility guarantees.");
692
693#define BUILTIN_LOCALS_METHODDEF    \
694    {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
695
696static PyObject *
697builtin_locals_impl(PyObject *module);
698
699static PyObject *
700builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
701{
702    return builtin_locals_impl(module);
703}
704
705PyDoc_STRVAR(builtin_oct__doc__,
706"oct($module, number, /)\n"
707"--\n"
708"\n"
709"Return the octal representation of an integer.\n"
710"\n"
711"   >>> oct(342391)\n"
712"   \'0o1234567\'");
713
714#define BUILTIN_OCT_METHODDEF    \
715    {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
716
717PyDoc_STRVAR(builtin_ord__doc__,
718"ord($module, c, /)\n"
719"--\n"
720"\n"
721"Return the Unicode code point for a one-character string.");
722
723#define BUILTIN_ORD_METHODDEF    \
724    {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
725
726PyDoc_STRVAR(builtin_pow__doc__,
727"pow($module, /, base, exp, mod=None)\n"
728"--\n"
729"\n"
730"Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments\n"
731"\n"
732"Some types, such as ints, are able to use a more efficient algorithm when\n"
733"invoked using the three argument form.");
734
735#define BUILTIN_POW_METHODDEF    \
736    {"pow", _PyCFunction_CAST(builtin_pow), METH_FASTCALL|METH_KEYWORDS, builtin_pow__doc__},
737
738static PyObject *
739builtin_pow_impl(PyObject *module, PyObject *base, PyObject *exp,
740                 PyObject *mod);
741
742static PyObject *
743builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
744{
745    PyObject *return_value = NULL;
746    static const char * const _keywords[] = {"base", "exp", "mod", NULL};
747    static _PyArg_Parser _parser = {NULL, _keywords, "pow", 0};
748    PyObject *argsbuf[3];
749    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
750    PyObject *base;
751    PyObject *exp;
752    PyObject *mod = Py_None;
753
754    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
755    if (!args) {
756        goto exit;
757    }
758    base = args[0];
759    exp = args[1];
760    if (!noptargs) {
761        goto skip_optional_pos;
762    }
763    mod = args[2];
764skip_optional_pos:
765    return_value = builtin_pow_impl(module, base, exp, mod);
766
767exit:
768    return return_value;
769}
770
771PyDoc_STRVAR(builtin_print__doc__,
772"print($module, /, *args, sep=\' \', end=\'\\n\', file=None, flush=False)\n"
773"--\n"
774"\n"
775"Prints the values to a stream, or to sys.stdout by default.\n"
776"\n"
777"  sep\n"
778"    string inserted between values, default a space.\n"
779"  end\n"
780"    string appended after the last value, default a newline.\n"
781"  file\n"
782"    a file-like object (stream); defaults to the current sys.stdout.\n"
783"  flush\n"
784"    whether to forcibly flush the stream.");
785
786#define BUILTIN_PRINT_METHODDEF    \
787    {"print", _PyCFunction_CAST(builtin_print), METH_FASTCALL|METH_KEYWORDS, builtin_print__doc__},
788
789static PyObject *
790builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep,
791                   PyObject *end, PyObject *file, int flush);
792
793static PyObject *
794builtin_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
795{
796    PyObject *return_value = NULL;
797    static const char * const _keywords[] = {"sep", "end", "file", "flush", NULL};
798    static _PyArg_Parser _parser = {NULL, _keywords, "print", 0};
799    PyObject *argsbuf[5];
800    Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
801    PyObject *__clinic_args = NULL;
802    PyObject *sep = Py_None;
803    PyObject *end = Py_None;
804    PyObject *file = Py_None;
805    int flush = 0;
806
807    args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf);
808    if (!args) {
809        goto exit;
810    }
811    __clinic_args = args[0];
812    if (!noptargs) {
813        goto skip_optional_kwonly;
814    }
815    if (args[1]) {
816        sep = args[1];
817        if (!--noptargs) {
818            goto skip_optional_kwonly;
819        }
820    }
821    if (args[2]) {
822        end = args[2];
823        if (!--noptargs) {
824            goto skip_optional_kwonly;
825        }
826    }
827    if (args[3]) {
828        file = args[3];
829        if (!--noptargs) {
830            goto skip_optional_kwonly;
831        }
832    }
833    flush = PyObject_IsTrue(args[4]);
834    if (flush < 0) {
835        goto exit;
836    }
837skip_optional_kwonly:
838    return_value = builtin_print_impl(module, __clinic_args, sep, end, file, flush);
839
840exit:
841    Py_XDECREF(__clinic_args);
842    return return_value;
843}
844
845PyDoc_STRVAR(builtin_input__doc__,
846"input($module, prompt=\'\', /)\n"
847"--\n"
848"\n"
849"Read a string from standard input.  The trailing newline is stripped.\n"
850"\n"
851"The prompt string, if given, is printed to standard output without a\n"
852"trailing newline before reading input.\n"
853"\n"
854"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
855"On *nix systems, readline is used if available.");
856
857#define BUILTIN_INPUT_METHODDEF    \
858    {"input", _PyCFunction_CAST(builtin_input), METH_FASTCALL, builtin_input__doc__},
859
860static PyObject *
861builtin_input_impl(PyObject *module, PyObject *prompt);
862
863static PyObject *
864builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
865{
866    PyObject *return_value = NULL;
867    PyObject *prompt = NULL;
868
869    if (!_PyArg_CheckPositional("input", nargs, 0, 1)) {
870        goto exit;
871    }
872    if (nargs < 1) {
873        goto skip_optional;
874    }
875    prompt = args[0];
876skip_optional:
877    return_value = builtin_input_impl(module, prompt);
878
879exit:
880    return return_value;
881}
882
883PyDoc_STRVAR(builtin_repr__doc__,
884"repr($module, obj, /)\n"
885"--\n"
886"\n"
887"Return the canonical string representation of the object.\n"
888"\n"
889"For many object types, including most builtins, eval(repr(obj)) == obj.");
890
891#define BUILTIN_REPR_METHODDEF    \
892    {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
893
894PyDoc_STRVAR(builtin_round__doc__,
895"round($module, /, number, ndigits=None)\n"
896"--\n"
897"\n"
898"Round a number to a given precision in decimal digits.\n"
899"\n"
900"The return value is an integer if ndigits is omitted or None.  Otherwise\n"
901"the return value has the same type as the number.  ndigits may be negative.");
902
903#define BUILTIN_ROUND_METHODDEF    \
904    {"round", _PyCFunction_CAST(builtin_round), METH_FASTCALL|METH_KEYWORDS, builtin_round__doc__},
905
906static PyObject *
907builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits);
908
909static PyObject *
910builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
911{
912    PyObject *return_value = NULL;
913    static const char * const _keywords[] = {"number", "ndigits", NULL};
914    static _PyArg_Parser _parser = {NULL, _keywords, "round", 0};
915    PyObject *argsbuf[2];
916    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
917    PyObject *number;
918    PyObject *ndigits = Py_None;
919
920    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
921    if (!args) {
922        goto exit;
923    }
924    number = args[0];
925    if (!noptargs) {
926        goto skip_optional_pos;
927    }
928    ndigits = args[1];
929skip_optional_pos:
930    return_value = builtin_round_impl(module, number, ndigits);
931
932exit:
933    return return_value;
934}
935
936PyDoc_STRVAR(builtin_sum__doc__,
937"sum($module, iterable, /, start=0)\n"
938"--\n"
939"\n"
940"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
941"\n"
942"When the iterable is empty, return the start value.\n"
943"This function is intended specifically for use with numeric values and may\n"
944"reject non-numeric types.");
945
946#define BUILTIN_SUM_METHODDEF    \
947    {"sum", _PyCFunction_CAST(builtin_sum), METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__},
948
949static PyObject *
950builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
951
952static PyObject *
953builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
954{
955    PyObject *return_value = NULL;
956    static const char * const _keywords[] = {"", "start", NULL};
957    static _PyArg_Parser _parser = {NULL, _keywords, "sum", 0};
958    PyObject *argsbuf[2];
959    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
960    PyObject *iterable;
961    PyObject *start = NULL;
962
963    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
964    if (!args) {
965        goto exit;
966    }
967    iterable = args[0];
968    if (!noptargs) {
969        goto skip_optional_pos;
970    }
971    start = args[1];
972skip_optional_pos:
973    return_value = builtin_sum_impl(module, iterable, start);
974
975exit:
976    return return_value;
977}
978
979PyDoc_STRVAR(builtin_isinstance__doc__,
980"isinstance($module, obj, class_or_tuple, /)\n"
981"--\n"
982"\n"
983"Return whether an object is an instance of a class or of a subclass thereof.\n"
984"\n"
985"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
986"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
987"or ...`` etc.");
988
989#define BUILTIN_ISINSTANCE_METHODDEF    \
990    {"isinstance", _PyCFunction_CAST(builtin_isinstance), METH_FASTCALL, builtin_isinstance__doc__},
991
992static PyObject *
993builtin_isinstance_impl(PyObject *module, PyObject *obj,
994                        PyObject *class_or_tuple);
995
996static PyObject *
997builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
998{
999    PyObject *return_value = NULL;
1000    PyObject *obj;
1001    PyObject *class_or_tuple;
1002
1003    if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
1004        goto exit;
1005    }
1006    obj = args[0];
1007    class_or_tuple = args[1];
1008    return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
1009
1010exit:
1011    return return_value;
1012}
1013
1014PyDoc_STRVAR(builtin_issubclass__doc__,
1015"issubclass($module, cls, class_or_tuple, /)\n"
1016"--\n"
1017"\n"
1018"Return whether \'cls\' is derived from another class or is the same class.\n"
1019"\n"
1020"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
1021"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
1022"or ...``.");
1023
1024#define BUILTIN_ISSUBCLASS_METHODDEF    \
1025    {"issubclass", _PyCFunction_CAST(builtin_issubclass), METH_FASTCALL, builtin_issubclass__doc__},
1026
1027static PyObject *
1028builtin_issubclass_impl(PyObject *module, PyObject *cls,
1029                        PyObject *class_or_tuple);
1030
1031static PyObject *
1032builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1033{
1034    PyObject *return_value = NULL;
1035    PyObject *cls;
1036    PyObject *class_or_tuple;
1037
1038    if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
1039        goto exit;
1040    }
1041    cls = args[0];
1042    class_or_tuple = args[1];
1043    return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
1044
1045exit:
1046    return return_value;
1047}
1048/*[clinic end generated code: output=c45d5fe414f7a8d7 input=a9049054013a1b77]*/
1049