Branch data Line data Source code
1 : : /*[clinic input]
2 : : preserve
3 : : [clinic start generated code]*/
4 : :
5 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 : : # include "pycore_gc.h" // PyGC_Head
7 : : # include "pycore_runtime.h" // _Py_ID()
8 : : #endif
9 : :
10 : :
11 : : PyDoc_STRVAR(builtin___import____doc__,
12 : : "__import__($module, /, name, globals=None, locals=None, fromlist=(),\n"
13 : : " level=0)\n"
14 : : "--\n"
15 : : "\n"
16 : : "Import a module.\n"
17 : : "\n"
18 : : "Because this function is meant for use by the Python\n"
19 : : "interpreter and not for general use, it is better to use\n"
20 : : "importlib.import_module() to programmatically import a module.\n"
21 : : "\n"
22 : : "The globals argument is only used to determine the context;\n"
23 : : "they are not modified. The locals argument is unused. The fromlist\n"
24 : : "should be a list of names to emulate ``from name import ...``, or an\n"
25 : : "empty list to emulate ``import name``.\n"
26 : : "When importing a module from a package, note that __import__(\'A.B\', ...)\n"
27 : : "returns package A when fromlist is empty, but its submodule B when\n"
28 : : "fromlist is not empty. The level argument is used to determine whether to\n"
29 : : "perform absolute or relative imports: 0 is absolute, while a positive number\n"
30 : : "is the number of parent directories to search relative to the current module.");
31 : :
32 : : #define BUILTIN___IMPORT___METHODDEF \
33 : : {"__import__", _PyCFunction_CAST(builtin___import__), METH_FASTCALL|METH_KEYWORDS, builtin___import____doc__},
34 : :
35 : : static PyObject *
36 : : builtin___import___impl(PyObject *module, PyObject *name, PyObject *globals,
37 : : PyObject *locals, PyObject *fromlist, int level);
38 : :
39 : : static PyObject *
40 : 1059 : builtin___import__(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
41 : : {
42 : 1059 : PyObject *return_value = NULL;
43 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
44 : :
45 : : #define NUM_KEYWORDS 5
46 : : static struct {
47 : : PyGC_Head _this_is_not_used;
48 : : PyObject_VAR_HEAD
49 : : PyObject *ob_item[NUM_KEYWORDS];
50 : : } _kwtuple = {
51 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
52 : : .ob_item = { &_Py_ID(name), &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(fromlist), &_Py_ID(level), },
53 : : };
54 : : #undef NUM_KEYWORDS
55 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
56 : :
57 : : #else // !Py_BUILD_CORE
58 : : # define KWTUPLE NULL
59 : : #endif // !Py_BUILD_CORE
60 : :
61 : : static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL};
62 : : static _PyArg_Parser _parser = {
63 : : .keywords = _keywords,
64 : : .fname = "__import__",
65 : : .kwtuple = KWTUPLE,
66 : : };
67 : : #undef KWTUPLE
68 : : PyObject *argsbuf[5];
69 [ + + ]: 1059 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
70 : : PyObject *name;
71 : 1059 : PyObject *globals = NULL;
72 : 1059 : PyObject *locals = NULL;
73 : 1059 : PyObject *fromlist = NULL;
74 : 1059 : int level = 0;
75 : :
76 [ + + + - : 1059 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf);
+ - - + ]
77 [ - + ]: 1059 : if (!args) {
78 : 0 : goto exit;
79 : : }
80 : 1059 : name = args[0];
81 [ + + ]: 1059 : if (!noptargs) {
82 : 67 : goto skip_optional_pos;
83 : : }
84 [ + + ]: 992 : if (args[1]) {
85 : 942 : globals = args[1];
86 [ - + ]: 942 : if (!--noptargs) {
87 : 0 : goto skip_optional_pos;
88 : : }
89 : : }
90 [ + + ]: 992 : if (args[2]) {
91 : 942 : locals = args[2];
92 [ - + ]: 942 : if (!--noptargs) {
93 : 0 : goto skip_optional_pos;
94 : : }
95 : : }
96 [ + - ]: 992 : if (args[3]) {
97 : 992 : fromlist = args[3];
98 [ + + ]: 992 : if (!--noptargs) {
99 : 1 : goto skip_optional_pos;
100 : : }
101 : : }
102 : 991 : level = _PyLong_AsInt(args[4]);
103 [ - + - - ]: 991 : if (level == -1 && PyErr_Occurred()) {
104 : 0 : goto exit;
105 : : }
106 : 991 : skip_optional_pos:
107 : 1059 : return_value = builtin___import___impl(module, name, globals, locals, fromlist, level);
108 : :
109 : 1059 : exit:
110 : 1059 : return return_value;
111 : : }
112 : :
113 : : PyDoc_STRVAR(builtin_abs__doc__,
114 : : "abs($module, x, /)\n"
115 : : "--\n"
116 : : "\n"
117 : : "Return the absolute value of the argument.");
118 : :
119 : : #define BUILTIN_ABS_METHODDEF \
120 : : {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__},
121 : :
122 : : PyDoc_STRVAR(builtin_all__doc__,
123 : : "all($module, iterable, /)\n"
124 : : "--\n"
125 : : "\n"
126 : : "Return True if bool(x) is True for all values x in the iterable.\n"
127 : : "\n"
128 : : "If the iterable is empty, return True.");
129 : :
130 : : #define BUILTIN_ALL_METHODDEF \
131 : : {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__},
132 : :
133 : : PyDoc_STRVAR(builtin_any__doc__,
134 : : "any($module, iterable, /)\n"
135 : : "--\n"
136 : : "\n"
137 : : "Return True if bool(x) is True for any x in the iterable.\n"
138 : : "\n"
139 : : "If the iterable is empty, return False.");
140 : :
141 : : #define BUILTIN_ANY_METHODDEF \
142 : : {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__},
143 : :
144 : : PyDoc_STRVAR(builtin_ascii__doc__,
145 : : "ascii($module, obj, /)\n"
146 : : "--\n"
147 : : "\n"
148 : : "Return an ASCII-only representation of an object.\n"
149 : : "\n"
150 : : "As repr(), return a string containing a printable representation of an\n"
151 : : "object, but escape the non-ASCII characters in the string returned by\n"
152 : : "repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n"
153 : : "to that returned by repr() in Python 2.");
154 : :
155 : : #define BUILTIN_ASCII_METHODDEF \
156 : : {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__},
157 : :
158 : : PyDoc_STRVAR(builtin_bin__doc__,
159 : : "bin($module, number, /)\n"
160 : : "--\n"
161 : : "\n"
162 : : "Return the binary representation of an integer.\n"
163 : : "\n"
164 : : " >>> bin(2796202)\n"
165 : : " \'0b1010101010101010101010\'");
166 : :
167 : : #define BUILTIN_BIN_METHODDEF \
168 : : {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__},
169 : :
170 : : PyDoc_STRVAR(builtin_callable__doc__,
171 : : "callable($module, obj, /)\n"
172 : : "--\n"
173 : : "\n"
174 : : "Return whether the object is callable (i.e., some kind of function).\n"
175 : : "\n"
176 : : "Note that classes are callable, as are instances of classes with a\n"
177 : : "__call__() method.");
178 : :
179 : : #define BUILTIN_CALLABLE_METHODDEF \
180 : : {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__},
181 : :
182 : : PyDoc_STRVAR(builtin_format__doc__,
183 : : "format($module, value, format_spec=\'\', /)\n"
184 : : "--\n"
185 : : "\n"
186 : : "Return type(value).__format__(value, format_spec)\n"
187 : : "\n"
188 : : "Many built-in types implement format_spec according to the\n"
189 : : "Format Specification Mini-language. See help(\'FORMATTING\').\n"
190 : : "\n"
191 : : "If type(value) does not supply a method named __format__\n"
192 : : "and format_spec is empty, then str(value) is returned.\n"
193 : : "See also help(\'SPECIALMETHODS\').");
194 : :
195 : : #define BUILTIN_FORMAT_METHODDEF \
196 : : {"format", _PyCFunction_CAST(builtin_format), METH_FASTCALL, builtin_format__doc__},
197 : :
198 : : static PyObject *
199 : : builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec);
200 : :
201 : : static PyObject *
202 : 0 : builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
203 : : {
204 : 0 : PyObject *return_value = NULL;
205 : : PyObject *value;
206 : 0 : PyObject *format_spec = NULL;
207 : :
208 [ # # # # : 0 : if (!_PyArg_CheckPositional("format", nargs, 1, 2)) {
# # ]
209 : 0 : goto exit;
210 : : }
211 : 0 : value = args[0];
212 [ # # ]: 0 : if (nargs < 2) {
213 : 0 : goto skip_optional;
214 : : }
215 [ # # ]: 0 : if (!PyUnicode_Check(args[1])) {
216 : 0 : _PyArg_BadArgument("format", "argument 2", "str", args[1]);
217 : 0 : goto exit;
218 : : }
219 [ # # ]: 0 : if (PyUnicode_READY(args[1]) == -1) {
220 : 0 : goto exit;
221 : : }
222 : 0 : format_spec = args[1];
223 : 0 : skip_optional:
224 : 0 : return_value = builtin_format_impl(module, value, format_spec);
225 : :
226 : 0 : exit:
227 : 0 : return return_value;
228 : : }
229 : :
230 : : PyDoc_STRVAR(builtin_chr__doc__,
231 : : "chr($module, i, /)\n"
232 : : "--\n"
233 : : "\n"
234 : : "Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
235 : :
236 : : #define BUILTIN_CHR_METHODDEF \
237 : : {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
238 : :
239 : : static PyObject *
240 : : builtin_chr_impl(PyObject *module, int i);
241 : :
242 : : static PyObject *
243 : 96 : builtin_chr(PyObject *module, PyObject *arg)
244 : : {
245 : 96 : PyObject *return_value = NULL;
246 : : int i;
247 : :
248 : 96 : i = _PyLong_AsInt(arg);
249 [ - + - - ]: 96 : if (i == -1 && PyErr_Occurred()) {
250 : 0 : goto exit;
251 : : }
252 : 96 : return_value = builtin_chr_impl(module, i);
253 : :
254 : 96 : exit:
255 : 96 : return return_value;
256 : : }
257 : :
258 : : PyDoc_STRVAR(builtin_compile__doc__,
259 : : "compile($module, /, source, filename, mode, flags=0,\n"
260 : : " dont_inherit=False, optimize=-1, *, _feature_version=-1)\n"
261 : : "--\n"
262 : : "\n"
263 : : "Compile source into a code object that can be executed by exec() or eval().\n"
264 : : "\n"
265 : : "The source code may represent a Python module, statement or expression.\n"
266 : : "The filename will be used for run-time error messages.\n"
267 : : "The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
268 : : "single (interactive) statement, or \'eval\' to compile an expression.\n"
269 : : "The flags argument, if present, controls which future statements influence\n"
270 : : "the compilation of the code.\n"
271 : : "The dont_inherit argument, if true, stops the compilation inheriting\n"
272 : : "the effects of any future statements in effect in the code calling\n"
273 : : "compile; if absent or false these statements do influence the compilation,\n"
274 : : "in addition to any features explicitly specified.");
275 : :
276 : : #define BUILTIN_COMPILE_METHODDEF \
277 : : {"compile", _PyCFunction_CAST(builtin_compile), METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__},
278 : :
279 : : static PyObject *
280 : : builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
281 : : const char *mode, int flags, int dont_inherit,
282 : : int optimize, int feature_version);
283 : :
284 : : static PyObject *
285 : 267 : builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
286 : : {
287 : 267 : PyObject *return_value = NULL;
288 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
289 : :
290 : : #define NUM_KEYWORDS 7
291 : : static struct {
292 : : PyGC_Head _this_is_not_used;
293 : : PyObject_VAR_HEAD
294 : : PyObject *ob_item[NUM_KEYWORDS];
295 : : } _kwtuple = {
296 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
297 : : .ob_item = { &_Py_ID(source), &_Py_ID(filename), &_Py_ID(mode), &_Py_ID(flags), &_Py_ID(dont_inherit), &_Py_ID(optimize), &_Py_ID(_feature_version), },
298 : : };
299 : : #undef NUM_KEYWORDS
300 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
301 : :
302 : : #else // !Py_BUILD_CORE
303 : : # define KWTUPLE NULL
304 : : #endif // !Py_BUILD_CORE
305 : :
306 : : static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "_feature_version", NULL};
307 : : static _PyArg_Parser _parser = {
308 : : .keywords = _keywords,
309 : : .fname = "compile",
310 : : .kwtuple = KWTUPLE,
311 : : };
312 : : #undef KWTUPLE
313 : : PyObject *argsbuf[7];
314 [ + + ]: 267 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
315 : : PyObject *source;
316 : : PyObject *filename;
317 : : const char *mode;
318 : 267 : int flags = 0;
319 : 267 : int dont_inherit = 0;
320 : 267 : int optimize = -1;
321 : 267 : int feature_version = -1;
322 : :
323 [ + + + - : 267 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf);
+ - - + ]
324 [ - + ]: 267 : if (!args) {
325 : 0 : goto exit;
326 : : }
327 : 267 : source = args[0];
328 [ - + ]: 267 : if (!PyUnicode_FSDecoder(args[1], &filename)) {
329 : 0 : goto exit;
330 : : }
331 [ - + ]: 267 : if (!PyUnicode_Check(args[2])) {
332 : 0 : _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]);
333 : 0 : goto exit;
334 : : }
335 : : Py_ssize_t mode_length;
336 : 267 : mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length);
337 [ - + ]: 267 : if (mode == NULL) {
338 : 0 : goto exit;
339 : : }
340 [ - + ]: 267 : if (strlen(mode) != (size_t)mode_length) {
341 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
342 : 0 : goto exit;
343 : : }
344 [ - + ]: 267 : if (!noptargs) {
345 : 0 : goto skip_optional_pos;
346 : : }
347 [ + + ]: 267 : if (args[3]) {
348 : 88 : flags = _PyLong_AsInt(args[3]);
349 [ - + - - ]: 88 : if (flags == -1 && PyErr_Occurred()) {
350 : 0 : goto exit;
351 : : }
352 [ - + ]: 88 : if (!--noptargs) {
353 : 0 : goto skip_optional_pos;
354 : : }
355 : : }
356 [ + + ]: 267 : if (args[4]) {
357 : 235 : dont_inherit = PyObject_IsTrue(args[4]);
358 [ - + ]: 235 : if (dont_inherit < 0) {
359 : 0 : goto exit;
360 : : }
361 [ + + ]: 235 : if (!--noptargs) {
362 : 56 : goto skip_optional_pos;
363 : : }
364 : : }
365 [ + + ]: 211 : if (args[5]) {
366 : 179 : optimize = _PyLong_AsInt(args[5]);
367 [ + + - + ]: 179 : if (optimize == -1 && PyErr_Occurred()) {
368 : 0 : goto exit;
369 : : }
370 [ - + ]: 179 : if (!--noptargs) {
371 : 179 : goto skip_optional_pos;
372 : : }
373 : : }
374 : 32 : skip_optional_pos:
375 [ + + ]: 267 : if (!noptargs) {
376 : 235 : goto skip_optional_kwonly;
377 : : }
378 : 32 : feature_version = _PyLong_AsInt(args[6]);
379 [ + - + - ]: 32 : if (feature_version == -1 && PyErr_Occurred()) {
380 : 0 : goto exit;
381 : : }
382 : 32 : skip_optional_kwonly:
383 : 267 : return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version);
384 : :
385 : 267 : exit:
386 : 267 : return return_value;
387 : : }
388 : :
389 : : PyDoc_STRVAR(builtin_dir__doc__,
390 : : "dir($module, arg=<unrepresentable>, /)\n"
391 : : "--\n"
392 : : "\n"
393 : : "Show attributes of an object.\n"
394 : : "\n"
395 : : "If called without an argument, return the names in the current scope.\n"
396 : : "Else, return an alphabetized list of names comprising (some of) the attributes\n"
397 : : "of the given object, and of attributes reachable from it.\n"
398 : : "If the object supplies a method named __dir__, it will be used; otherwise\n"
399 : : "the default dir() logic is used and returns:\n"
400 : : " for a module object: the module\'s attributes.\n"
401 : : " for a class object: its attributes, and recursively the attributes\n"
402 : : " of its bases.\n"
403 : : " for any other object: its attributes, its class\'s attributes, and\n"
404 : : " recursively the attributes of its class\'s base classes.");
405 : :
406 : : #define BUILTIN_DIR_METHODDEF \
407 : : {"dir", _PyCFunction_CAST(builtin_dir), METH_FASTCALL, builtin_dir__doc__},
408 : :
409 : : static PyObject *
410 : : builtin_dir_impl(PyObject *module, PyObject *arg);
411 : :
412 : : static PyObject *
413 : 30 : builtin_dir(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
414 : : {
415 : 30 : PyObject *return_value = NULL;
416 : 30 : PyObject *arg = NULL;
417 : :
418 [ + - - + : 30 : if (!_PyArg_CheckPositional("dir", nargs, 0, 1)) {
- - ]
419 : 0 : goto exit;
420 : : }
421 [ - + ]: 30 : if (nargs < 1) {
422 : 0 : goto skip_optional;
423 : : }
424 : 30 : arg = args[0];
425 : 30 : skip_optional:
426 : 30 : return_value = builtin_dir_impl(module, arg);
427 : :
428 : 30 : exit:
429 : 30 : return return_value;
430 : : }
431 : :
432 : : PyDoc_STRVAR(builtin_divmod__doc__,
433 : : "divmod($module, x, y, /)\n"
434 : : "--\n"
435 : : "\n"
436 : : "Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
437 : :
438 : : #define BUILTIN_DIVMOD_METHODDEF \
439 : : {"divmod", _PyCFunction_CAST(builtin_divmod), METH_FASTCALL, builtin_divmod__doc__},
440 : :
441 : : static PyObject *
442 : : builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
443 : :
444 : : static PyObject *
445 : 148 : builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
446 : : {
447 : 148 : PyObject *return_value = NULL;
448 : : PyObject *x;
449 : : PyObject *y;
450 : :
451 [ + - - + : 148 : if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
- - ]
452 : 0 : goto exit;
453 : : }
454 : 148 : x = args[0];
455 : 148 : y = args[1];
456 : 148 : return_value = builtin_divmod_impl(module, x, y);
457 : :
458 : 148 : exit:
459 : 148 : return return_value;
460 : : }
461 : :
462 : : PyDoc_STRVAR(builtin_eval__doc__,
463 : : "eval($module, source, globals=None, locals=None, /)\n"
464 : : "--\n"
465 : : "\n"
466 : : "Evaluate the given source in the context of globals and locals.\n"
467 : : "\n"
468 : : "The source may be a string representing a Python expression\n"
469 : : "or a code object as returned by compile().\n"
470 : : "The globals must be a dictionary and locals can be any mapping,\n"
471 : : "defaulting to the current globals and locals.\n"
472 : : "If only globals is given, locals defaults to it.");
473 : :
474 : : #define BUILTIN_EVAL_METHODDEF \
475 : : {"eval", _PyCFunction_CAST(builtin_eval), METH_FASTCALL, builtin_eval__doc__},
476 : :
477 : : static PyObject *
478 : : builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
479 : : PyObject *locals);
480 : :
481 : : static PyObject *
482 : 57 : builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
483 : : {
484 : 57 : PyObject *return_value = NULL;
485 : : PyObject *source;
486 : 57 : PyObject *globals = Py_None;
487 : 57 : PyObject *locals = Py_None;
488 : :
489 [ + - - + : 57 : if (!_PyArg_CheckPositional("eval", nargs, 1, 3)) {
- - ]
490 : 0 : goto exit;
491 : : }
492 : 57 : source = args[0];
493 [ - + ]: 57 : if (nargs < 2) {
494 : 0 : goto skip_optional;
495 : : }
496 : 57 : globals = args[1];
497 [ + - ]: 57 : if (nargs < 3) {
498 : 57 : goto skip_optional;
499 : : }
500 : 0 : locals = args[2];
501 : 57 : skip_optional:
502 : 57 : return_value = builtin_eval_impl(module, source, globals, locals);
503 : :
504 : 57 : exit:
505 : 57 : return return_value;
506 : : }
507 : :
508 : : PyDoc_STRVAR(builtin_exec__doc__,
509 : : "exec($module, source, globals=None, locals=None, /, *, closure=None)\n"
510 : : "--\n"
511 : : "\n"
512 : : "Execute the given source in the context of globals and locals.\n"
513 : : "\n"
514 : : "The source may be a string representing one or more Python statements\n"
515 : : "or a code object as returned by compile().\n"
516 : : "The globals must be a dictionary and locals can be any mapping,\n"
517 : : "defaulting to the current globals and locals.\n"
518 : : "If only globals is given, locals defaults to it.\n"
519 : : "The closure must be a tuple of cellvars, and can only be used\n"
520 : : "when source is a code object requiring exactly that many cellvars.");
521 : :
522 : : #define BUILTIN_EXEC_METHODDEF \
523 : : {"exec", _PyCFunction_CAST(builtin_exec), METH_FASTCALL|METH_KEYWORDS, builtin_exec__doc__},
524 : :
525 : : static PyObject *
526 : : builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
527 : : PyObject *locals, PyObject *closure);
528 : :
529 : : static PyObject *
530 : 698 : builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
531 : : {
532 : 698 : PyObject *return_value = NULL;
533 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
534 : :
535 : : #define NUM_KEYWORDS 1
536 : : static struct {
537 : : PyGC_Head _this_is_not_used;
538 : : PyObject_VAR_HEAD
539 : : PyObject *ob_item[NUM_KEYWORDS];
540 : : } _kwtuple = {
541 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
542 : : .ob_item = { &_Py_ID(closure), },
543 : : };
544 : : #undef NUM_KEYWORDS
545 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
546 : :
547 : : #else // !Py_BUILD_CORE
548 : : # define KWTUPLE NULL
549 : : #endif // !Py_BUILD_CORE
550 : :
551 : : static const char * const _keywords[] = {"", "", "", "closure", NULL};
552 : : static _PyArg_Parser _parser = {
553 : : .keywords = _keywords,
554 : : .fname = "exec",
555 : : .kwtuple = KWTUPLE,
556 : : };
557 : : #undef KWTUPLE
558 : : PyObject *argsbuf[4];
559 [ - + ]: 698 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
560 : : PyObject *source;
561 : 698 : PyObject *globals = Py_None;
562 : 698 : PyObject *locals = Py_None;
563 : 698 : PyObject *closure = NULL;
564 : :
565 [ + - + - : 698 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
+ - - + ]
566 [ - + ]: 698 : if (!args) {
567 : 0 : goto exit;
568 : : }
569 : 698 : source = args[0];
570 [ - + ]: 698 : if (nargs < 2) {
571 : 0 : goto skip_optional_posonly;
572 : : }
573 : 698 : noptargs--;
574 : 698 : globals = args[1];
575 [ + - ]: 698 : if (nargs < 3) {
576 : 698 : goto skip_optional_posonly;
577 : : }
578 : 0 : noptargs--;
579 : 0 : locals = args[2];
580 : 698 : skip_optional_posonly:
581 [ + - ]: 698 : if (!noptargs) {
582 : 698 : goto skip_optional_kwonly;
583 : : }
584 : 0 : closure = args[3];
585 : 698 : skip_optional_kwonly:
586 : 698 : return_value = builtin_exec_impl(module, source, globals, locals, closure);
587 : :
588 : 698 : exit:
589 : 698 : return return_value;
590 : : }
591 : :
592 : : PyDoc_STRVAR(builtin_getattr__doc__,
593 : : "getattr($module, object, name, default=<unrepresentable>, /)\n"
594 : : "--\n"
595 : : "\n"
596 : : "Get a named attribute from an object.\n"
597 : : "\n"
598 : : "getattr(x, \'y\') is equivalent to x.y\n"
599 : : "When a default argument is given, it is returned when the attribute doesn\'t\n"
600 : : "exist; without it, an exception is raised in that case.");
601 : :
602 : : #define BUILTIN_GETATTR_METHODDEF \
603 : : {"getattr", _PyCFunction_CAST(builtin_getattr), METH_FASTCALL, builtin_getattr__doc__},
604 : :
605 : : static PyObject *
606 : : builtin_getattr_impl(PyObject *module, PyObject *object, PyObject *name,
607 : : PyObject *default_value);
608 : :
609 : : static PyObject *
610 : 130711 : builtin_getattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
611 : : {
612 : 130711 : PyObject *return_value = NULL;
613 : : PyObject *object;
614 : : PyObject *name;
615 : 130711 : PyObject *default_value = NULL;
616 : :
617 [ + - - + : 130711 : if (!_PyArg_CheckPositional("getattr", nargs, 2, 3)) {
- - ]
618 : 0 : goto exit;
619 : : }
620 : 130711 : object = args[0];
621 : 130711 : name = args[1];
622 [ + + ]: 130711 : if (nargs < 3) {
623 : 23849 : goto skip_optional;
624 : : }
625 : 106862 : default_value = args[2];
626 : 130711 : skip_optional:
627 : 130711 : return_value = builtin_getattr_impl(module, object, name, default_value);
628 : :
629 : 130711 : exit:
630 : 130711 : return return_value;
631 : : }
632 : :
633 : : PyDoc_STRVAR(builtin_globals__doc__,
634 : : "globals($module, /)\n"
635 : : "--\n"
636 : : "\n"
637 : : "Return the dictionary containing the current scope\'s global variables.\n"
638 : : "\n"
639 : : "NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
640 : : "global scope and vice-versa.");
641 : :
642 : : #define BUILTIN_GLOBALS_METHODDEF \
643 : : {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
644 : :
645 : : static PyObject *
646 : : builtin_globals_impl(PyObject *module);
647 : :
648 : : static PyObject *
649 : 322 : builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
650 : : {
651 : 322 : return builtin_globals_impl(module);
652 : : }
653 : :
654 : : PyDoc_STRVAR(builtin_hasattr__doc__,
655 : : "hasattr($module, obj, name, /)\n"
656 : : "--\n"
657 : : "\n"
658 : : "Return whether the object has an attribute with the given name.\n"
659 : : "\n"
660 : : "This is done by calling getattr(obj, name) and catching AttributeError.");
661 : :
662 : : #define BUILTIN_HASATTR_METHODDEF \
663 : : {"hasattr", _PyCFunction_CAST(builtin_hasattr), METH_FASTCALL, builtin_hasattr__doc__},
664 : :
665 : : static PyObject *
666 : : builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
667 : :
668 : : static PyObject *
669 : 6976 : builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
670 : : {
671 : 6976 : PyObject *return_value = NULL;
672 : : PyObject *obj;
673 : : PyObject *name;
674 : :
675 [ + - - + : 6976 : if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
- - ]
676 : 0 : goto exit;
677 : : }
678 : 6976 : obj = args[0];
679 : 6976 : name = args[1];
680 : 6976 : return_value = builtin_hasattr_impl(module, obj, name);
681 : :
682 : 6976 : exit:
683 : 6976 : return return_value;
684 : : }
685 : :
686 : : PyDoc_STRVAR(builtin_id__doc__,
687 : : "id($module, obj, /)\n"
688 : : "--\n"
689 : : "\n"
690 : : "Return the identity of an object.\n"
691 : : "\n"
692 : : "This is guaranteed to be unique among simultaneously existing objects.\n"
693 : : "(CPython uses the object\'s memory address.)");
694 : :
695 : : #define BUILTIN_ID_METHODDEF \
696 : : {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
697 : :
698 : : PyDoc_STRVAR(builtin_next__doc__,
699 : : "next($module, iterator, default=<unrepresentable>, /)\n"
700 : : "--\n"
701 : : "\n"
702 : : "Return the next item from the iterator.\n"
703 : : "\n"
704 : : "If default is given and the iterator is exhausted,\n"
705 : : "it is returned instead of raising StopIteration.");
706 : :
707 : : #define BUILTIN_NEXT_METHODDEF \
708 : : {"next", _PyCFunction_CAST(builtin_next), METH_FASTCALL, builtin_next__doc__},
709 : :
710 : : static PyObject *
711 : : builtin_next_impl(PyObject *module, PyObject *iterator,
712 : : PyObject *default_value);
713 : :
714 : : static PyObject *
715 : 196835 : builtin_next(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
716 : : {
717 : 196835 : PyObject *return_value = NULL;
718 : : PyObject *iterator;
719 : 196835 : PyObject *default_value = NULL;
720 : :
721 [ + - - + : 196835 : if (!_PyArg_CheckPositional("next", nargs, 1, 2)) {
- - ]
722 : 0 : goto exit;
723 : : }
724 : 196835 : iterator = args[0];
725 [ + - ]: 196835 : if (nargs < 2) {
726 : 196835 : goto skip_optional;
727 : : }
728 : 0 : default_value = args[1];
729 : 196835 : skip_optional:
730 : 196835 : return_value = builtin_next_impl(module, iterator, default_value);
731 : :
732 : 196835 : exit:
733 : 196835 : return return_value;
734 : : }
735 : :
736 : : PyDoc_STRVAR(builtin_setattr__doc__,
737 : : "setattr($module, obj, name, value, /)\n"
738 : : "--\n"
739 : : "\n"
740 : : "Sets the named attribute on the given object to the specified value.\n"
741 : : "\n"
742 : : "setattr(x, \'y\', v) is equivalent to ``x.y = v``");
743 : :
744 : : #define BUILTIN_SETATTR_METHODDEF \
745 : : {"setattr", _PyCFunction_CAST(builtin_setattr), METH_FASTCALL, builtin_setattr__doc__},
746 : :
747 : : static PyObject *
748 : : builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
749 : : PyObject *value);
750 : :
751 : : static PyObject *
752 : 2427 : builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
753 : : {
754 : 2427 : PyObject *return_value = NULL;
755 : : PyObject *obj;
756 : : PyObject *name;
757 : : PyObject *value;
758 : :
759 [ + - - + : 2427 : if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) {
- - ]
760 : 0 : goto exit;
761 : : }
762 : 2427 : obj = args[0];
763 : 2427 : name = args[1];
764 : 2427 : value = args[2];
765 : 2427 : return_value = builtin_setattr_impl(module, obj, name, value);
766 : :
767 : 2427 : exit:
768 : 2427 : return return_value;
769 : : }
770 : :
771 : : PyDoc_STRVAR(builtin_delattr__doc__,
772 : : "delattr($module, obj, name, /)\n"
773 : : "--\n"
774 : : "\n"
775 : : "Deletes the named attribute from the given object.\n"
776 : : "\n"
777 : : "delattr(x, \'y\') is equivalent to ``del x.y``");
778 : :
779 : : #define BUILTIN_DELATTR_METHODDEF \
780 : : {"delattr", _PyCFunction_CAST(builtin_delattr), METH_FASTCALL, builtin_delattr__doc__},
781 : :
782 : : static PyObject *
783 : : builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
784 : :
785 : : static PyObject *
786 : 187 : builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
787 : : {
788 : 187 : PyObject *return_value = NULL;
789 : : PyObject *obj;
790 : : PyObject *name;
791 : :
792 [ + - - + : 187 : if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
- - ]
793 : 0 : goto exit;
794 : : }
795 : 187 : obj = args[0];
796 : 187 : name = args[1];
797 : 187 : return_value = builtin_delattr_impl(module, obj, name);
798 : :
799 : 187 : exit:
800 : 187 : return return_value;
801 : : }
802 : :
803 : : PyDoc_STRVAR(builtin_hash__doc__,
804 : : "hash($module, obj, /)\n"
805 : : "--\n"
806 : : "\n"
807 : : "Return the hash value for the given object.\n"
808 : : "\n"
809 : : "Two objects that compare equal must also have the same hash value, but the\n"
810 : : "reverse is not necessarily true.");
811 : :
812 : : #define BUILTIN_HASH_METHODDEF \
813 : : {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
814 : :
815 : : PyDoc_STRVAR(builtin_hex__doc__,
816 : : "hex($module, number, /)\n"
817 : : "--\n"
818 : : "\n"
819 : : "Return the hexadecimal representation of an integer.\n"
820 : : "\n"
821 : : " >>> hex(12648430)\n"
822 : : " \'0xc0ffee\'");
823 : :
824 : : #define BUILTIN_HEX_METHODDEF \
825 : : {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
826 : :
827 : : PyDoc_STRVAR(builtin_iter__doc__,
828 : : "iter($module, object, sentinel=<unrepresentable>, /)\n"
829 : : "--\n"
830 : : "\n"
831 : : "Get an iterator from an object.\n"
832 : : "\n"
833 : : "In the first form, the argument must supply its own iterator, or be a sequence.\n"
834 : : "In the second form, the callable is called until it returns the sentinel.");
835 : :
836 : : #define BUILTIN_ITER_METHODDEF \
837 : : {"iter", _PyCFunction_CAST(builtin_iter), METH_FASTCALL, builtin_iter__doc__},
838 : :
839 : : static PyObject *
840 : : builtin_iter_impl(PyObject *module, PyObject *object, PyObject *sentinel);
841 : :
842 : : static PyObject *
843 : 428 : builtin_iter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
844 : : {
845 : 428 : PyObject *return_value = NULL;
846 : : PyObject *object;
847 : 428 : PyObject *sentinel = NULL;
848 : :
849 [ + - - + : 428 : if (!_PyArg_CheckPositional("iter", nargs, 1, 2)) {
- - ]
850 : 0 : goto exit;
851 : : }
852 : 428 : object = args[0];
853 [ + - ]: 428 : if (nargs < 2) {
854 : 428 : goto skip_optional;
855 : : }
856 : 0 : sentinel = args[1];
857 : 428 : skip_optional:
858 : 428 : return_value = builtin_iter_impl(module, object, sentinel);
859 : :
860 : 428 : exit:
861 : 428 : return return_value;
862 : : }
863 : :
864 : : PyDoc_STRVAR(builtin_aiter__doc__,
865 : : "aiter($module, async_iterable, /)\n"
866 : : "--\n"
867 : : "\n"
868 : : "Return an AsyncIterator for an AsyncIterable object.");
869 : :
870 : : #define BUILTIN_AITER_METHODDEF \
871 : : {"aiter", (PyCFunction)builtin_aiter, METH_O, builtin_aiter__doc__},
872 : :
873 : : PyDoc_STRVAR(builtin_anext__doc__,
874 : : "anext($module, aiterator, default=<unrepresentable>, /)\n"
875 : : "--\n"
876 : : "\n"
877 : : "async anext(aiterator[, default])\n"
878 : : "\n"
879 : : "Return the next item from the async iterator. If default is given and the async\n"
880 : : "iterator is exhausted, it is returned instead of raising StopAsyncIteration.");
881 : :
882 : : #define BUILTIN_ANEXT_METHODDEF \
883 : : {"anext", _PyCFunction_CAST(builtin_anext), METH_FASTCALL, builtin_anext__doc__},
884 : :
885 : : static PyObject *
886 : : builtin_anext_impl(PyObject *module, PyObject *aiterator,
887 : : PyObject *default_value);
888 : :
889 : : static PyObject *
890 : 0 : builtin_anext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
891 : : {
892 : 0 : PyObject *return_value = NULL;
893 : : PyObject *aiterator;
894 : 0 : PyObject *default_value = NULL;
895 : :
896 [ # # # # : 0 : if (!_PyArg_CheckPositional("anext", nargs, 1, 2)) {
# # ]
897 : 0 : goto exit;
898 : : }
899 : 0 : aiterator = args[0];
900 [ # # ]: 0 : if (nargs < 2) {
901 : 0 : goto skip_optional;
902 : : }
903 : 0 : default_value = args[1];
904 : 0 : skip_optional:
905 : 0 : return_value = builtin_anext_impl(module, aiterator, default_value);
906 : :
907 : 0 : exit:
908 : 0 : return return_value;
909 : : }
910 : :
911 : : PyDoc_STRVAR(builtin_len__doc__,
912 : : "len($module, obj, /)\n"
913 : : "--\n"
914 : : "\n"
915 : : "Return the number of items in a container.");
916 : :
917 : : #define BUILTIN_LEN_METHODDEF \
918 : : {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
919 : :
920 : : PyDoc_STRVAR(builtin_locals__doc__,
921 : : "locals($module, /)\n"
922 : : "--\n"
923 : : "\n"
924 : : "Return a dictionary containing the current scope\'s local variables.\n"
925 : : "\n"
926 : : "NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
927 : : "the local scope and vice-versa is *implementation dependent* and not\n"
928 : : "covered by any backwards compatibility guarantees.");
929 : :
930 : : #define BUILTIN_LOCALS_METHODDEF \
931 : : {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
932 : :
933 : : static PyObject *
934 : : builtin_locals_impl(PyObject *module);
935 : :
936 : : static PyObject *
937 : 2 : builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
938 : : {
939 : 2 : return builtin_locals_impl(module);
940 : : }
941 : :
942 : : PyDoc_STRVAR(builtin_oct__doc__,
943 : : "oct($module, number, /)\n"
944 : : "--\n"
945 : : "\n"
946 : : "Return the octal representation of an integer.\n"
947 : : "\n"
948 : : " >>> oct(342391)\n"
949 : : " \'0o1234567\'");
950 : :
951 : : #define BUILTIN_OCT_METHODDEF \
952 : : {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
953 : :
954 : : PyDoc_STRVAR(builtin_ord__doc__,
955 : : "ord($module, c, /)\n"
956 : : "--\n"
957 : : "\n"
958 : : "Return the Unicode code point for a one-character string.");
959 : :
960 : : #define BUILTIN_ORD_METHODDEF \
961 : : {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
962 : :
963 : : PyDoc_STRVAR(builtin_pow__doc__,
964 : : "pow($module, /, base, exp, mod=None)\n"
965 : : "--\n"
966 : : "\n"
967 : : "Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments\n"
968 : : "\n"
969 : : "Some types, such as ints, are able to use a more efficient algorithm when\n"
970 : : "invoked using the three argument form.");
971 : :
972 : : #define BUILTIN_POW_METHODDEF \
973 : : {"pow", _PyCFunction_CAST(builtin_pow), METH_FASTCALL|METH_KEYWORDS, builtin_pow__doc__},
974 : :
975 : : static PyObject *
976 : : builtin_pow_impl(PyObject *module, PyObject *base, PyObject *exp,
977 : : PyObject *mod);
978 : :
979 : : static PyObject *
980 : 0 : builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
981 : : {
982 : 0 : PyObject *return_value = NULL;
983 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
984 : :
985 : : #define NUM_KEYWORDS 3
986 : : static struct {
987 : : PyGC_Head _this_is_not_used;
988 : : PyObject_VAR_HEAD
989 : : PyObject *ob_item[NUM_KEYWORDS];
990 : : } _kwtuple = {
991 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
992 : : .ob_item = { &_Py_ID(base), &_Py_ID(exp), &_Py_ID(mod), },
993 : : };
994 : : #undef NUM_KEYWORDS
995 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
996 : :
997 : : #else // !Py_BUILD_CORE
998 : : # define KWTUPLE NULL
999 : : #endif // !Py_BUILD_CORE
1000 : :
1001 : : static const char * const _keywords[] = {"base", "exp", "mod", NULL};
1002 : : static _PyArg_Parser _parser = {
1003 : : .keywords = _keywords,
1004 : : .fname = "pow",
1005 : : .kwtuple = KWTUPLE,
1006 : : };
1007 : : #undef KWTUPLE
1008 : : PyObject *argsbuf[3];
1009 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1010 : : PyObject *base;
1011 : : PyObject *exp;
1012 : 0 : PyObject *mod = Py_None;
1013 : :
1014 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
# # # # ]
1015 [ # # ]: 0 : if (!args) {
1016 : 0 : goto exit;
1017 : : }
1018 : 0 : base = args[0];
1019 : 0 : exp = args[1];
1020 [ # # ]: 0 : if (!noptargs) {
1021 : 0 : goto skip_optional_pos;
1022 : : }
1023 : 0 : mod = args[2];
1024 : 0 : skip_optional_pos:
1025 : 0 : return_value = builtin_pow_impl(module, base, exp, mod);
1026 : :
1027 : 0 : exit:
1028 : 0 : return return_value;
1029 : : }
1030 : :
1031 : : PyDoc_STRVAR(builtin_print__doc__,
1032 : : "print($module, /, *args, sep=\' \', end=\'\\n\', file=None, flush=False)\n"
1033 : : "--\n"
1034 : : "\n"
1035 : : "Prints the values to a stream, or to sys.stdout by default.\n"
1036 : : "\n"
1037 : : " sep\n"
1038 : : " string inserted between values, default a space.\n"
1039 : : " end\n"
1040 : : " string appended after the last value, default a newline.\n"
1041 : : " file\n"
1042 : : " a file-like object (stream); defaults to the current sys.stdout.\n"
1043 : : " flush\n"
1044 : : " whether to forcibly flush the stream.");
1045 : :
1046 : : #define BUILTIN_PRINT_METHODDEF \
1047 : : {"print", _PyCFunction_CAST(builtin_print), METH_FASTCALL|METH_KEYWORDS, builtin_print__doc__},
1048 : :
1049 : : static PyObject *
1050 : : builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep,
1051 : : PyObject *end, PyObject *file, int flush);
1052 : :
1053 : : static PyObject *
1054 : 48 : builtin_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1055 : : {
1056 : 48 : PyObject *return_value = NULL;
1057 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1058 : :
1059 : : #define NUM_KEYWORDS 4
1060 : : static struct {
1061 : : PyGC_Head _this_is_not_used;
1062 : : PyObject_VAR_HEAD
1063 : : PyObject *ob_item[NUM_KEYWORDS];
1064 : : } _kwtuple = {
1065 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1066 : : .ob_item = { &_Py_ID(sep), &_Py_ID(end), &_Py_ID(file), &_Py_ID(flush), },
1067 : : };
1068 : : #undef NUM_KEYWORDS
1069 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1070 : :
1071 : : #else // !Py_BUILD_CORE
1072 : : # define KWTUPLE NULL
1073 : : #endif // !Py_BUILD_CORE
1074 : :
1075 : : static const char * const _keywords[] = {"sep", "end", "file", "flush", NULL};
1076 : : static _PyArg_Parser _parser = {
1077 : : .keywords = _keywords,
1078 : : .fname = "print",
1079 : : .kwtuple = KWTUPLE,
1080 : : };
1081 : : #undef KWTUPLE
1082 : : PyObject *argsbuf[5];
1083 [ + + ]: 48 : Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1084 : 48 : PyObject *__clinic_args = NULL;
1085 : 48 : PyObject *sep = Py_None;
1086 : 48 : PyObject *end = Py_None;
1087 : 48 : PyObject *file = Py_None;
1088 : 48 : int flush = 0;
1089 : :
1090 : 48 : args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf);
1091 [ - + ]: 48 : if (!args) {
1092 : 0 : goto exit;
1093 : : }
1094 : 48 : __clinic_args = args[0];
1095 [ + + ]: 48 : if (!noptargs) {
1096 : 10 : goto skip_optional_kwonly;
1097 : : }
1098 [ - + ]: 38 : if (args[1]) {
1099 : 0 : sep = args[1];
1100 [ # # ]: 0 : if (!--noptargs) {
1101 : 0 : goto skip_optional_kwonly;
1102 : : }
1103 : : }
1104 [ + + ]: 38 : if (args[2]) {
1105 : 36 : end = args[2];
1106 [ - + ]: 36 : if (!--noptargs) {
1107 : 0 : goto skip_optional_kwonly;
1108 : : }
1109 : : }
1110 [ + + ]: 38 : if (args[3]) {
1111 : 36 : file = args[3];
1112 [ + - ]: 36 : if (!--noptargs) {
1113 : 36 : goto skip_optional_kwonly;
1114 : : }
1115 : : }
1116 : 2 : flush = PyObject_IsTrue(args[4]);
1117 [ - + ]: 2 : if (flush < 0) {
1118 : 0 : goto exit;
1119 : : }
1120 : 2 : skip_optional_kwonly:
1121 : 48 : return_value = builtin_print_impl(module, __clinic_args, sep, end, file, flush);
1122 : :
1123 : 48 : exit:
1124 : 48 : Py_XDECREF(__clinic_args);
1125 : 48 : return return_value;
1126 : : }
1127 : :
1128 : : PyDoc_STRVAR(builtin_input__doc__,
1129 : : "input($module, prompt=\'\', /)\n"
1130 : : "--\n"
1131 : : "\n"
1132 : : "Read a string from standard input. The trailing newline is stripped.\n"
1133 : : "\n"
1134 : : "The prompt string, if given, is printed to standard output without a\n"
1135 : : "trailing newline before reading input.\n"
1136 : : "\n"
1137 : : "If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
1138 : : "On *nix systems, readline is used if available.");
1139 : :
1140 : : #define BUILTIN_INPUT_METHODDEF \
1141 : : {"input", _PyCFunction_CAST(builtin_input), METH_FASTCALL, builtin_input__doc__},
1142 : :
1143 : : static PyObject *
1144 : : builtin_input_impl(PyObject *module, PyObject *prompt);
1145 : :
1146 : : static PyObject *
1147 : 0 : builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1148 : : {
1149 : 0 : PyObject *return_value = NULL;
1150 : 0 : PyObject *prompt = NULL;
1151 : :
1152 [ # # # # : 0 : if (!_PyArg_CheckPositional("input", nargs, 0, 1)) {
# # ]
1153 : 0 : goto exit;
1154 : : }
1155 [ # # ]: 0 : if (nargs < 1) {
1156 : 0 : goto skip_optional;
1157 : : }
1158 : 0 : prompt = args[0];
1159 : 0 : skip_optional:
1160 : 0 : return_value = builtin_input_impl(module, prompt);
1161 : :
1162 : 0 : exit:
1163 : 0 : return return_value;
1164 : : }
1165 : :
1166 : : PyDoc_STRVAR(builtin_repr__doc__,
1167 : : "repr($module, obj, /)\n"
1168 : : "--\n"
1169 : : "\n"
1170 : : "Return the canonical string representation of the object.\n"
1171 : : "\n"
1172 : : "For many object types, including most builtins, eval(repr(obj)) == obj.");
1173 : :
1174 : : #define BUILTIN_REPR_METHODDEF \
1175 : : {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
1176 : :
1177 : : PyDoc_STRVAR(builtin_round__doc__,
1178 : : "round($module, /, number, ndigits=None)\n"
1179 : : "--\n"
1180 : : "\n"
1181 : : "Round a number to a given precision in decimal digits.\n"
1182 : : "\n"
1183 : : "The return value is an integer if ndigits is omitted or None. Otherwise\n"
1184 : : "the return value has the same type as the number. ndigits may be negative.");
1185 : :
1186 : : #define BUILTIN_ROUND_METHODDEF \
1187 : : {"round", _PyCFunction_CAST(builtin_round), METH_FASTCALL|METH_KEYWORDS, builtin_round__doc__},
1188 : :
1189 : : static PyObject *
1190 : : builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits);
1191 : :
1192 : : static PyObject *
1193 : 18 : builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1194 : : {
1195 : 18 : PyObject *return_value = NULL;
1196 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1197 : :
1198 : : #define NUM_KEYWORDS 2
1199 : : static struct {
1200 : : PyGC_Head _this_is_not_used;
1201 : : PyObject_VAR_HEAD
1202 : : PyObject *ob_item[NUM_KEYWORDS];
1203 : : } _kwtuple = {
1204 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1205 : : .ob_item = { &_Py_ID(number), &_Py_ID(ndigits), },
1206 : : };
1207 : : #undef NUM_KEYWORDS
1208 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1209 : :
1210 : : #else // !Py_BUILD_CORE
1211 : : # define KWTUPLE NULL
1212 : : #endif // !Py_BUILD_CORE
1213 : :
1214 : : static const char * const _keywords[] = {"number", "ndigits", NULL};
1215 : : static _PyArg_Parser _parser = {
1216 : : .keywords = _keywords,
1217 : : .fname = "round",
1218 : : .kwtuple = KWTUPLE,
1219 : : };
1220 : : #undef KWTUPLE
1221 : : PyObject *argsbuf[2];
1222 [ - + ]: 18 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1223 : : PyObject *number;
1224 : 18 : PyObject *ndigits = Py_None;
1225 : :
1226 [ + - + - : 18 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ - - + ]
1227 [ - + ]: 18 : if (!args) {
1228 : 0 : goto exit;
1229 : : }
1230 : 18 : number = args[0];
1231 [ + + ]: 18 : if (!noptargs) {
1232 : 12 : goto skip_optional_pos;
1233 : : }
1234 : 6 : ndigits = args[1];
1235 : 18 : skip_optional_pos:
1236 : 18 : return_value = builtin_round_impl(module, number, ndigits);
1237 : :
1238 : 18 : exit:
1239 : 18 : return return_value;
1240 : : }
1241 : :
1242 : : PyDoc_STRVAR(builtin_vars__doc__,
1243 : : "vars($module, object=<unrepresentable>, /)\n"
1244 : : "--\n"
1245 : : "\n"
1246 : : "Show vars.\n"
1247 : : "\n"
1248 : : "Without arguments, equivalent to locals().\n"
1249 : : "With an argument, equivalent to object.__dict__.");
1250 : :
1251 : : #define BUILTIN_VARS_METHODDEF \
1252 : : {"vars", _PyCFunction_CAST(builtin_vars), METH_FASTCALL, builtin_vars__doc__},
1253 : :
1254 : : static PyObject *
1255 : : builtin_vars_impl(PyObject *module, PyObject *object);
1256 : :
1257 : : static PyObject *
1258 : 25 : builtin_vars(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1259 : : {
1260 : 25 : PyObject *return_value = NULL;
1261 : 25 : PyObject *object = NULL;
1262 : :
1263 [ + - - + : 25 : if (!_PyArg_CheckPositional("vars", nargs, 0, 1)) {
- - ]
1264 : 0 : goto exit;
1265 : : }
1266 [ - + ]: 25 : if (nargs < 1) {
1267 : 0 : goto skip_optional;
1268 : : }
1269 : 25 : object = args[0];
1270 : 25 : skip_optional:
1271 : 25 : return_value = builtin_vars_impl(module, object);
1272 : :
1273 : 25 : exit:
1274 : 25 : return return_value;
1275 : : }
1276 : :
1277 : : PyDoc_STRVAR(builtin_sum__doc__,
1278 : : "sum($module, iterable, /, start=0)\n"
1279 : : "--\n"
1280 : : "\n"
1281 : : "Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
1282 : : "\n"
1283 : : "When the iterable is empty, return the start value.\n"
1284 : : "This function is intended specifically for use with numeric values and may\n"
1285 : : "reject non-numeric types.");
1286 : :
1287 : : #define BUILTIN_SUM_METHODDEF \
1288 : : {"sum", _PyCFunction_CAST(builtin_sum), METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__},
1289 : :
1290 : : static PyObject *
1291 : : builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
1292 : :
1293 : : static PyObject *
1294 : 835 : builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1295 : : {
1296 : 835 : PyObject *return_value = NULL;
1297 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1298 : :
1299 : : #define NUM_KEYWORDS 1
1300 : : static struct {
1301 : : PyGC_Head _this_is_not_used;
1302 : : PyObject_VAR_HEAD
1303 : : PyObject *ob_item[NUM_KEYWORDS];
1304 : : } _kwtuple = {
1305 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1306 : : .ob_item = { &_Py_ID(start), },
1307 : : };
1308 : : #undef NUM_KEYWORDS
1309 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1310 : :
1311 : : #else // !Py_BUILD_CORE
1312 : : # define KWTUPLE NULL
1313 : : #endif // !Py_BUILD_CORE
1314 : :
1315 : : static const char * const _keywords[] = {"", "start", NULL};
1316 : : static _PyArg_Parser _parser = {
1317 : : .keywords = _keywords,
1318 : : .fname = "sum",
1319 : : .kwtuple = KWTUPLE,
1320 : : };
1321 : : #undef KWTUPLE
1322 : : PyObject *argsbuf[2];
1323 [ - + ]: 835 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1324 : : PyObject *iterable;
1325 : 835 : PyObject *start = NULL;
1326 : :
1327 [ + - + - : 835 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ - - + ]
1328 [ - + ]: 835 : if (!args) {
1329 : 0 : goto exit;
1330 : : }
1331 : 835 : iterable = args[0];
1332 [ + - ]: 835 : if (!noptargs) {
1333 : 835 : goto skip_optional_pos;
1334 : : }
1335 : 0 : start = args[1];
1336 : 835 : skip_optional_pos:
1337 : 835 : return_value = builtin_sum_impl(module, iterable, start);
1338 : :
1339 : 835 : exit:
1340 : 835 : return return_value;
1341 : : }
1342 : :
1343 : : PyDoc_STRVAR(builtin_isinstance__doc__,
1344 : : "isinstance($module, obj, class_or_tuple, /)\n"
1345 : : "--\n"
1346 : : "\n"
1347 : : "Return whether an object is an instance of a class or of a subclass thereof.\n"
1348 : : "\n"
1349 : : "A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
1350 : : "check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
1351 : : "or ...`` etc.");
1352 : :
1353 : : #define BUILTIN_ISINSTANCE_METHODDEF \
1354 : : {"isinstance", _PyCFunction_CAST(builtin_isinstance), METH_FASTCALL, builtin_isinstance__doc__},
1355 : :
1356 : : static PyObject *
1357 : : builtin_isinstance_impl(PyObject *module, PyObject *obj,
1358 : : PyObject *class_or_tuple);
1359 : :
1360 : : static PyObject *
1361 : 595 : builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1362 : : {
1363 : 595 : PyObject *return_value = NULL;
1364 : : PyObject *obj;
1365 : : PyObject *class_or_tuple;
1366 : :
1367 [ + - - + : 595 : if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
- - ]
1368 : 0 : goto exit;
1369 : : }
1370 : 595 : obj = args[0];
1371 : 595 : class_or_tuple = args[1];
1372 : 595 : return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
1373 : :
1374 : 595 : exit:
1375 : 595 : return return_value;
1376 : : }
1377 : :
1378 : : PyDoc_STRVAR(builtin_issubclass__doc__,
1379 : : "issubclass($module, cls, class_or_tuple, /)\n"
1380 : : "--\n"
1381 : : "\n"
1382 : : "Return whether \'cls\' is derived from another class or is the same class.\n"
1383 : : "\n"
1384 : : "A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
1385 : : "check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
1386 : : "or ...``.");
1387 : :
1388 : : #define BUILTIN_ISSUBCLASS_METHODDEF \
1389 : : {"issubclass", _PyCFunction_CAST(builtin_issubclass), METH_FASTCALL, builtin_issubclass__doc__},
1390 : :
1391 : : static PyObject *
1392 : : builtin_issubclass_impl(PyObject *module, PyObject *cls,
1393 : : PyObject *class_or_tuple);
1394 : :
1395 : : static PyObject *
1396 : 2274 : builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1397 : : {
1398 : 2274 : PyObject *return_value = NULL;
1399 : : PyObject *cls;
1400 : : PyObject *class_or_tuple;
1401 : :
1402 [ + - - + : 2274 : if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
- - ]
1403 : 0 : goto exit;
1404 : : }
1405 : 2274 : cls = args[0];
1406 : 2274 : class_or_tuple = args[1];
1407 : 2274 : return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
1408 : :
1409 : 2274 : exit:
1410 : 2274 : return return_value;
1411 : : }
1412 : : /*[clinic end generated code: output=84a04e7446debf58 input=a9049054013a1b77]*/
|