Line data Source code
1 : /*[clinic input]
2 : preserve
3 : [clinic start generated code]*/
4 :
5 : PyDoc_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 :
29 : static PyObject *
30 : builtin___import___impl(PyObject *module, PyObject *name, PyObject *globals,
31 : PyObject *locals, PyObject *fromlist, int level);
32 :
33 : static PyObject *
34 655299 : builtin___import__(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
35 : {
36 655299 : 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 655299 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
41 : PyObject *name;
42 655299 : PyObject *globals = NULL;
43 655299 : PyObject *locals = NULL;
44 655299 : PyObject *fromlist = NULL;
45 655299 : int level = 0;
46 :
47 655299 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf);
48 655299 : if (!args) {
49 1 : goto exit;
50 : }
51 655298 : name = args[0];
52 655298 : if (!noptargs) {
53 36680 : goto skip_optional_pos;
54 : }
55 618618 : if (args[1]) {
56 597526 : globals = args[1];
57 597526 : if (!--noptargs) {
58 0 : goto skip_optional_pos;
59 : }
60 : }
61 618618 : if (args[2]) {
62 597494 : locals = args[2];
63 597494 : if (!--noptargs) {
64 5 : goto skip_optional_pos;
65 : }
66 : }
67 618613 : if (args[3]) {
68 604873 : fromlist = args[3];
69 604873 : if (!--noptargs) {
70 2522 : goto skip_optional_pos;
71 : }
72 : }
73 616091 : level = _PyLong_AsInt(args[4]);
74 616091 : if (level == -1 && PyErr_Occurred()) {
75 0 : goto exit;
76 : }
77 616091 : skip_optional_pos:
78 655298 : return_value = builtin___import___impl(module, name, globals, locals, fromlist, level);
79 :
80 655299 : exit:
81 655299 : return return_value;
82 : }
83 :
84 : PyDoc_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 :
93 : PyDoc_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 :
104 : PyDoc_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 :
115 : PyDoc_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 :
129 : PyDoc_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 :
141 : PyDoc_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 :
153 : PyDoc_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 :
166 : static PyObject *
167 : builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec);
168 :
169 : static PyObject *
170 3350170 : builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
171 : {
172 3350170 : PyObject *return_value = NULL;
173 : PyObject *value;
174 3350170 : PyObject *format_spec = NULL;
175 :
176 3350170 : if (!_PyArg_CheckPositional("format", nargs, 1, 2)) {
177 0 : goto exit;
178 : }
179 3350170 : value = args[0];
180 3350170 : if (nargs < 2) {
181 160 : goto skip_optional;
182 : }
183 3350010 : if (!PyUnicode_Check(args[1])) {
184 2 : _PyArg_BadArgument("format", "argument 2", "str", args[1]);
185 2 : goto exit;
186 : }
187 3350010 : if (PyUnicode_READY(args[1]) == -1) {
188 0 : goto exit;
189 : }
190 3350010 : format_spec = args[1];
191 3350170 : skip_optional:
192 3350170 : return_value = builtin_format_impl(module, value, format_spec);
193 :
194 3350170 : exit:
195 3350170 : return return_value;
196 : }
197 :
198 : PyDoc_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 :
207 : static PyObject *
208 : builtin_chr_impl(PyObject *module, int i);
209 :
210 : static PyObject *
211 12080600 : builtin_chr(PyObject *module, PyObject *arg)
212 : {
213 12080600 : PyObject *return_value = NULL;
214 : int i;
215 :
216 12080600 : i = _PyLong_AsInt(arg);
217 12080600 : if (i == -1 && PyErr_Occurred()) {
218 1 : goto exit;
219 : }
220 12080600 : return_value = builtin_chr_impl(module, i);
221 :
222 12080600 : exit:
223 12080600 : return return_value;
224 : }
225 :
226 : PyDoc_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 :
247 : static PyObject *
248 : builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
249 : const char *mode, int flags, int dont_inherit,
250 : int optimize, int feature_version);
251 :
252 : static PyObject *
253 31039 : builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
254 : {
255 31039 : 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 31039 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
260 : PyObject *source;
261 : PyObject *filename;
262 : const char *mode;
263 31039 : int flags = 0;
264 31039 : int dont_inherit = 0;
265 31039 : int optimize = -1;
266 31039 : int feature_version = -1;
267 :
268 31039 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf);
269 31039 : if (!args) {
270 2 : goto exit;
271 : }
272 31037 : source = args[0];
273 31037 : if (!PyUnicode_FSDecoder(args[1], &filename)) {
274 1 : goto exit;
275 : }
276 31036 : if (!PyUnicode_Check(args[2])) {
277 0 : _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]);
278 0 : goto exit;
279 : }
280 : Py_ssize_t mode_length;
281 31036 : mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length);
282 31036 : if (mode == NULL) {
283 0 : goto exit;
284 : }
285 31036 : if (strlen(mode) != (size_t)mode_length) {
286 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
287 0 : goto exit;
288 : }
289 31036 : if (!noptargs) {
290 3150 : goto skip_optional_pos;
291 : }
292 27886 : if (args[3]) {
293 16190 : flags = _PyLong_AsInt(args[3]);
294 16190 : if (flags == -1 && PyErr_Occurred()) {
295 0 : goto exit;
296 : }
297 16190 : if (!--noptargs) {
298 767 : goto skip_optional_pos;
299 : }
300 : }
301 27119 : if (args[4]) {
302 15876 : dont_inherit = _PyLong_AsInt(args[4]);
303 15876 : if (dont_inherit == -1 && PyErr_Occurred()) {
304 0 : goto exit;
305 : }
306 15876 : if (!--noptargs) {
307 8150 : goto skip_optional_pos;
308 : }
309 : }
310 18969 : if (args[5]) {
311 7734 : optimize = _PyLong_AsInt(args[5]);
312 7734 : if (optimize == -1 && PyErr_Occurred()) {
313 0 : goto exit;
314 : }
315 7734 : if (!--noptargs) {
316 7734 : goto skip_optional_pos;
317 : }
318 : }
319 11235 : skip_optional_pos:
320 31036 : if (!noptargs) {
321 19801 : goto skip_optional_kwonly;
322 : }
323 11235 : feature_version = _PyLong_AsInt(args[6]);
324 11235 : if (feature_version == -1 && PyErr_Occurred()) {
325 0 : goto exit;
326 : }
327 11235 : skip_optional_kwonly:
328 31036 : return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version);
329 :
330 31039 : exit:
331 31039 : return return_value;
332 : }
333 :
334 : PyDoc_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 :
343 : static PyObject *
344 : builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
345 :
346 : static PyObject *
347 1376620 : builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
348 : {
349 1376620 : PyObject *return_value = NULL;
350 : PyObject *x;
351 : PyObject *y;
352 :
353 1376620 : if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
354 1 : goto exit;
355 : }
356 1376620 : x = args[0];
357 1376620 : y = args[1];
358 1376620 : return_value = builtin_divmod_impl(module, x, y);
359 :
360 1376620 : exit:
361 1376620 : return return_value;
362 : }
363 :
364 : PyDoc_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 :
379 : static PyObject *
380 : builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
381 : PyObject *locals);
382 :
383 : static PyObject *
384 72037 : builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
385 : {
386 72037 : PyObject *return_value = NULL;
387 : PyObject *source;
388 72037 : PyObject *globals = Py_None;
389 72037 : PyObject *locals = Py_None;
390 :
391 72037 : if (!_PyArg_CheckPositional("eval", nargs, 1, 3)) {
392 1 : goto exit;
393 : }
394 72036 : source = args[0];
395 72036 : if (nargs < 2) {
396 18528 : goto skip_optional;
397 : }
398 53508 : globals = args[1];
399 53508 : if (nargs < 3) {
400 52656 : goto skip_optional;
401 : }
402 852 : locals = args[2];
403 72036 : skip_optional:
404 72036 : return_value = builtin_eval_impl(module, source, globals, locals);
405 :
406 72037 : exit:
407 72037 : return return_value;
408 : }
409 :
410 : PyDoc_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 :
427 : static PyObject *
428 : builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
429 : PyObject *locals, PyObject *closure);
430 :
431 : static PyObject *
432 240078 : builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
433 : {
434 240078 : 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 240078 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
439 : PyObject *source;
440 240078 : PyObject *globals = Py_None;
441 240078 : PyObject *locals = Py_None;
442 240078 : PyObject *closure = NULL;
443 :
444 240078 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
445 240078 : if (!args) {
446 0 : goto exit;
447 : }
448 240078 : source = args[0];
449 240078 : if (nargs < 2) {
450 191 : goto skip_optional_posonly;
451 : }
452 239887 : noptargs--;
453 239887 : globals = args[1];
454 239887 : if (nargs < 3) {
455 236792 : goto skip_optional_posonly;
456 : }
457 3095 : noptargs--;
458 3095 : locals = args[2];
459 240078 : skip_optional_posonly:
460 240078 : if (!noptargs) {
461 240071 : goto skip_optional_kwonly;
462 : }
463 7 : closure = args[3];
464 240078 : skip_optional_kwonly:
465 240078 : return_value = builtin_exec_impl(module, source, globals, locals, closure);
466 :
467 240078 : exit:
468 240078 : return return_value;
469 : }
470 :
471 : PyDoc_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 :
483 : static PyObject *
484 : builtin_globals_impl(PyObject *module);
485 :
486 : static PyObject *
487 60783 : builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
488 : {
489 60783 : return builtin_globals_impl(module);
490 : }
491 :
492 : PyDoc_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 :
503 : static PyObject *
504 : builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
505 :
506 : static PyObject *
507 6174420 : builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
508 : {
509 6174420 : PyObject *return_value = NULL;
510 : PyObject *obj;
511 : PyObject *name;
512 :
513 6174420 : if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
514 2 : goto exit;
515 : }
516 6174420 : obj = args[0];
517 6174420 : name = args[1];
518 6174420 : return_value = builtin_hasattr_impl(module, obj, name);
519 :
520 6174420 : exit:
521 6174420 : return return_value;
522 : }
523 :
524 : PyDoc_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 :
536 : PyDoc_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 :
547 : static PyObject *
548 : builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
549 : PyObject *value);
550 :
551 : static PyObject *
552 1467980 : builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
553 : {
554 1467980 : PyObject *return_value = NULL;
555 : PyObject *obj;
556 : PyObject *name;
557 : PyObject *value;
558 :
559 1467980 : if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) {
560 5 : goto exit;
561 : }
562 1467970 : obj = args[0];
563 1467970 : name = args[1];
564 1467970 : value = args[2];
565 1467970 : return_value = builtin_setattr_impl(module, obj, name, value);
566 :
567 1467980 : exit:
568 1467980 : return return_value;
569 : }
570 :
571 : PyDoc_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 :
582 : static PyObject *
583 : builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
584 :
585 : static PyObject *
586 216030 : builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
587 : {
588 216030 : PyObject *return_value = NULL;
589 : PyObject *obj;
590 : PyObject *name;
591 :
592 216030 : if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
593 2 : goto exit;
594 : }
595 216028 : obj = args[0];
596 216028 : name = args[1];
597 216028 : return_value = builtin_delattr_impl(module, obj, name);
598 :
599 216030 : exit:
600 216030 : return return_value;
601 : }
602 :
603 : PyDoc_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 :
615 : PyDoc_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 :
627 : PyDoc_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 :
636 : PyDoc_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 :
648 : static PyObject *
649 : builtin_anext_impl(PyObject *module, PyObject *aiterator,
650 : PyObject *default_value);
651 :
652 : static PyObject *
653 116 : builtin_anext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
654 : {
655 116 : PyObject *return_value = NULL;
656 : PyObject *aiterator;
657 116 : PyObject *default_value = NULL;
658 :
659 116 : if (!_PyArg_CheckPositional("anext", nargs, 1, 2)) {
660 2 : goto exit;
661 : }
662 114 : aiterator = args[0];
663 114 : if (nargs < 2) {
664 82 : goto skip_optional;
665 : }
666 32 : default_value = args[1];
667 114 : skip_optional:
668 114 : return_value = builtin_anext_impl(module, aiterator, default_value);
669 :
670 116 : exit:
671 116 : return return_value;
672 : }
673 :
674 : PyDoc_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 :
683 : PyDoc_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 :
696 : static PyObject *
697 : builtin_locals_impl(PyObject *module);
698 :
699 : static PyObject *
700 1831 : builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
701 : {
702 1831 : return builtin_locals_impl(module);
703 : }
704 :
705 : PyDoc_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 :
717 : PyDoc_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 :
726 : PyDoc_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 :
738 : static PyObject *
739 : builtin_pow_impl(PyObject *module, PyObject *base, PyObject *exp,
740 : PyObject *mod);
741 :
742 : static PyObject *
743 116333 : builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
744 : {
745 116333 : 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 116333 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
750 : PyObject *base;
751 : PyObject *exp;
752 116333 : PyObject *mod = Py_None;
753 :
754 116333 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
755 116333 : if (!args) {
756 1 : goto exit;
757 : }
758 116332 : base = args[0];
759 116332 : exp = args[1];
760 116332 : if (!noptargs) {
761 18954 : goto skip_optional_pos;
762 : }
763 97378 : mod = args[2];
764 116332 : skip_optional_pos:
765 116332 : return_value = builtin_pow_impl(module, base, exp, mod);
766 :
767 116333 : exit:
768 116333 : return return_value;
769 : }
770 :
771 : PyDoc_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 :
789 : static PyObject *
790 : builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep,
791 : PyObject *end, PyObject *file, int flush);
792 :
793 : static PyObject *
794 109653 : builtin_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
795 : {
796 109653 : 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 109653 : Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
801 109653 : PyObject *__clinic_args = NULL;
802 109653 : PyObject *sep = Py_None;
803 109653 : PyObject *end = Py_None;
804 109653 : PyObject *file = Py_None;
805 109653 : int flush = 0;
806 :
807 109653 : args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf);
808 109653 : if (!args) {
809 1 : goto exit;
810 : }
811 109652 : __clinic_args = args[0];
812 109652 : if (!noptargs) {
813 29237 : goto skip_optional_kwonly;
814 : }
815 80415 : if (args[1]) {
816 78 : sep = args[1];
817 78 : if (!--noptargs) {
818 7 : goto skip_optional_kwonly;
819 : }
820 : }
821 80408 : if (args[2]) {
822 29190 : end = args[2];
823 29190 : if (!--noptargs) {
824 4699 : goto skip_optional_kwonly;
825 : }
826 : }
827 75709 : if (args[3]) {
828 74474 : file = args[3];
829 74474 : if (!--noptargs) {
830 74441 : goto skip_optional_kwonly;
831 : }
832 : }
833 1268 : flush = PyObject_IsTrue(args[4]);
834 1268 : if (flush < 0) {
835 0 : goto exit;
836 : }
837 1268 : skip_optional_kwonly:
838 109652 : return_value = builtin_print_impl(module, __clinic_args, sep, end, file, flush);
839 :
840 109653 : exit:
841 109653 : Py_XDECREF(__clinic_args);
842 109653 : return return_value;
843 : }
844 :
845 : PyDoc_STRVAR(builtin_input__doc__,
846 : "input($module, prompt=None, /)\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 :
860 : static PyObject *
861 : builtin_input_impl(PyObject *module, PyObject *prompt);
862 :
863 : static PyObject *
864 316 : builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
865 : {
866 316 : PyObject *return_value = NULL;
867 316 : PyObject *prompt = NULL;
868 :
869 316 : if (!_PyArg_CheckPositional("input", nargs, 0, 1)) {
870 2 : goto exit;
871 : }
872 314 : if (nargs < 1) {
873 12 : goto skip_optional;
874 : }
875 302 : prompt = args[0];
876 314 : skip_optional:
877 314 : return_value = builtin_input_impl(module, prompt);
878 :
879 316 : exit:
880 316 : return return_value;
881 : }
882 :
883 : PyDoc_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 :
894 : PyDoc_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 :
906 : static PyObject *
907 : builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits);
908 :
909 : static PyObject *
910 1303720 : builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
911 : {
912 1303720 : 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 1303720 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
917 : PyObject *number;
918 1303720 : PyObject *ndigits = Py_None;
919 :
920 1303720 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
921 1303720 : if (!args) {
922 2 : goto exit;
923 : }
924 1303720 : number = args[0];
925 1303720 : if (!noptargs) {
926 84909 : goto skip_optional_pos;
927 : }
928 1218810 : ndigits = args[1];
929 1303720 : skip_optional_pos:
930 1303720 : return_value = builtin_round_impl(module, number, ndigits);
931 :
932 1303720 : exit:
933 1303720 : return return_value;
934 : }
935 :
936 : PyDoc_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 :
949 : static PyObject *
950 : builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
951 :
952 : static PyObject *
953 428785 : builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
954 : {
955 428785 : 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 428785 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
960 : PyObject *iterable;
961 428785 : PyObject *start = NULL;
962 :
963 428785 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
964 428785 : if (!args) {
965 1 : goto exit;
966 : }
967 428784 : iterable = args[0];
968 428784 : if (!noptargs) {
969 370709 : goto skip_optional_pos;
970 : }
971 58075 : start = args[1];
972 428784 : skip_optional_pos:
973 428784 : return_value = builtin_sum_impl(module, iterable, start);
974 :
975 428785 : exit:
976 428785 : return return_value;
977 : }
978 :
979 : PyDoc_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 :
992 : static PyObject *
993 : builtin_isinstance_impl(PyObject *module, PyObject *obj,
994 : PyObject *class_or_tuple);
995 :
996 : static PyObject *
997 870383 : builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
998 : {
999 870383 : PyObject *return_value = NULL;
1000 : PyObject *obj;
1001 : PyObject *class_or_tuple;
1002 :
1003 870383 : if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
1004 1 : goto exit;
1005 : }
1006 870382 : obj = args[0];
1007 870382 : class_or_tuple = args[1];
1008 870382 : return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
1009 :
1010 870383 : exit:
1011 870383 : return return_value;
1012 : }
1013 :
1014 : PyDoc_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 :
1027 : static PyObject *
1028 : builtin_issubclass_impl(PyObject *module, PyObject *cls,
1029 : PyObject *class_or_tuple);
1030 :
1031 : static PyObject *
1032 1047430 : builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1033 : {
1034 1047430 : PyObject *return_value = NULL;
1035 : PyObject *cls;
1036 : PyObject *class_or_tuple;
1037 :
1038 1047430 : if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
1039 1 : goto exit;
1040 : }
1041 1047430 : cls = args[0];
1042 1047430 : class_or_tuple = args[1];
1043 1047430 : return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
1044 :
1045 1047430 : exit:
1046 1047430 : return return_value;
1047 : }
1048 : /*[clinic end generated code: output=a2c5c53e8aead7c3 input=a9049054013a1b77]*/
|