Coverage Report

Created: 2026-05-16 06:46

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