Coverage Report

Created: 2026-03-08 06:40

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
247k
{
42
247k
    PyObject *return_value = NULL;
43
247k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
44
45
247k
    #define NUM_KEYWORDS 5
46
247k
    static struct {
47
247k
        PyGC_Head _this_is_not_used;
48
247k
        PyObject_VAR_HEAD
49
247k
        Py_hash_t ob_hash;
50
247k
        PyObject *ob_item[NUM_KEYWORDS];
51
247k
    } _kwtuple = {
52
247k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
53
247k
        .ob_hash = -1,
54
247k
        .ob_item = { &_Py_ID(name), &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(fromlist), &_Py_ID(level), },
55
247k
    };
56
247k
    #undef NUM_KEYWORDS
57
247k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
58
59
    #else  // !Py_BUILD_CORE
60
    #  define KWTUPLE NULL
61
    #endif  // !Py_BUILD_CORE
62
63
247k
    static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL};
64
247k
    static _PyArg_Parser _parser = {
65
247k
        .keywords = _keywords,
66
247k
        .fname = "__import__",
67
247k
        .kwtuple = KWTUPLE,
68
247k
    };
69
247k
    #undef KWTUPLE
70
247k
    PyObject *argsbuf[5];
71
247k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
72
247k
    PyObject *name;
73
247k
    PyObject *globals = NULL;
74
247k
    PyObject *locals = NULL;
75
247k
    PyObject *fromlist = NULL;
76
247k
    int level = 0;
77
78
247k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
79
247k
            /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
80
247k
    if (!args) {
81
0
        goto exit;
82
0
    }
83
247k
    name = args[0];
84
247k
    if (!noptargs) {
85
856
        goto skip_optional_pos;
86
856
    }
87
246k
    if (args[1]) {
88
239k
        globals = args[1];
89
239k
        if (!--noptargs) {
90
0
            goto skip_optional_pos;
91
0
        }
92
239k
    }
93
246k
    if (args[2]) {
94
239k
        locals = args[2];
95
239k
        if (!--noptargs) {
96
0
            goto skip_optional_pos;
97
0
        }
98
239k
    }
99
246k
    if (args[3]) {
100
246k
        fromlist = args[3];
101
246k
        if (!--noptargs) {
102
0
            goto skip_optional_pos;
103
0
        }
104
246k
    }
105
246k
    level = PyLong_AsInt(args[4]);
106
246k
    if (level == -1 && PyErr_Occurred()) {
107
0
        goto exit;
108
0
    }
109
247k
skip_optional_pos:
110
247k
    return_value = builtin___import___impl(module, name, globals, locals, fromlist, level);
111
112
247k
exit:
113
247k
    return return_value;
114
247k
}
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
110k
{
364
110k
    PyObject *return_value = NULL;
365
110k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
366
367
110k
    #define NUM_KEYWORDS 8
368
110k
    static struct {
369
110k
        PyGC_Head _this_is_not_used;
370
110k
        PyObject_VAR_HEAD
371
110k
        Py_hash_t ob_hash;
372
110k
        PyObject *ob_item[NUM_KEYWORDS];
373
110k
    } _kwtuple = {
374
110k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
375
110k
        .ob_hash = -1,
376
110k
        .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
110k
    };
378
110k
    #undef NUM_KEYWORDS
379
110k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
380
381
    #else  // !Py_BUILD_CORE
382
    #  define KWTUPLE NULL
383
    #endif  // !Py_BUILD_CORE
384
385
110k
    static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "module", "_feature_version", NULL};
386
110k
    static _PyArg_Parser _parser = {
387
110k
        .keywords = _keywords,
388
110k
        .fname = "compile",
389
110k
        .kwtuple = KWTUPLE,
390
110k
    };
391
110k
    #undef KWTUPLE
392
110k
    PyObject *argsbuf[8];
393
110k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
394
110k
    PyObject *source;
395
110k
    PyObject *filename = NULL;
396
110k
    const char *mode;
397
110k
    int flags = 0;
398
110k
    int dont_inherit = 0;
399
110k
    int optimize = -1;
400
110k
    PyObject *modname = Py_None;
401
110k
    int feature_version = -1;
402
403
110k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
404
110k
            /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
405
110k
    if (!args) {
406
0
        goto exit;
407
0
    }
408
110k
    source = args[0];
409
110k
    if (!PyUnicode_FSDecoder(args[1], &filename)) {
410
0
        goto exit;
411
0
    }
412
110k
    if (!PyUnicode_Check(args[2])) {
413
0
        _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]);
414
0
        goto exit;
415
0
    }
416
110k
    Py_ssize_t mode_length;
417
110k
    mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length);
418
110k
    if (mode == NULL) {
419
0
        goto exit;
420
0
    }
421
110k
    if (strlen(mode) != (size_t)mode_length) {
422
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
423
0
        goto exit;
424
0
    }
425
110k
    if (!noptargs) {
426
32
        goto skip_optional_pos;
427
32
    }
428
110k
    if (args[3]) {
429
110k
        flags = PyLong_AsInt(args[3]);
430
110k
        if (flags == -1 && PyErr_Occurred()) {
431
0
            goto exit;
432
0
        }
433
110k
        if (!--noptargs) {
434
0
            goto skip_optional_pos;
435
0
        }
436
110k
    }
437
110k
    if (args[4]) {
438
164
        dont_inherit = PyObject_IsTrue(args[4]);
439
164
        if (dont_inherit < 0) {
440
0
            goto exit;
441
0
        }
442
164
        if (!--noptargs) {
443
0
            goto skip_optional_pos;
444
0
        }
445
164
    }
446
110k
    if (args[5]) {
447
110k
        optimize = PyLong_AsInt(args[5]);
448
110k
        if (optimize == -1 && PyErr_Occurred()) {
449
0
            goto exit;
450
0
        }
451
110k
        if (!--noptargs) {
452
0
            goto skip_optional_pos;
453
0
        }
454
110k
    }
455
110k
skip_optional_pos:
456
110k
    if (!noptargs) {
457
32
        goto skip_optional_kwonly;
458
32
    }
459
110k
    if (args[6]) {
460
110k
        modname = args[6];
461
110k
        if (!--noptargs) {
462
164
            goto skip_optional_kwonly;
463
164
        }
464
110k
    }
465
110k
    feature_version = PyLong_AsInt(args[7]);
466
110k
    if (feature_version == -1 && PyErr_Occurred()) {
467
0
        goto exit;
468
0
    }
469
110k
skip_optional_kwonly:
470
110k
    return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, modname, feature_version);
471
472
110k
exit:
473
    /* Cleanup for filename */
474
110k
    Py_XDECREF(filename);
475
476
110k
    return return_value;
477
110k
}
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
5.26k
{
494
5.26k
    PyObject *return_value = NULL;
495
5.26k
    PyObject *x;
496
5.26k
    PyObject *y;
497
498
5.26k
    if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
499
0
        goto exit;
500
0
    }
501
5.26k
    x = args[0];
502
5.26k
    y = args[1];
503
5.26k
    return_value = builtin_divmod_impl(module, x, y);
504
505
5.26k
exit:
506
5.26k
    return return_value;
507
5.26k
}
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
210
{
531
210
    PyObject *return_value = NULL;
532
210
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
533
534
210
    #define NUM_KEYWORDS 2
535
210
    static struct {
536
210
        PyGC_Head _this_is_not_used;
537
210
        PyObject_VAR_HEAD
538
210
        Py_hash_t ob_hash;
539
210
        PyObject *ob_item[NUM_KEYWORDS];
540
210
    } _kwtuple = {
541
210
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
542
210
        .ob_hash = -1,
543
210
        .ob_item = { &_Py_ID(globals), &_Py_ID(locals), },
544
210
    };
545
210
    #undef NUM_KEYWORDS
546
210
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
547
548
    #else  // !Py_BUILD_CORE
549
    #  define KWTUPLE NULL
550
    #endif  // !Py_BUILD_CORE
551
552
210
    static const char * const _keywords[] = {"", "globals", "locals", NULL};
553
210
    static _PyArg_Parser _parser = {
554
210
        .keywords = _keywords,
555
210
        .fname = "eval",
556
210
        .kwtuple = KWTUPLE,
557
210
    };
558
210
    #undef KWTUPLE
559
210
    PyObject *argsbuf[3];
560
210
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
561
210
    PyObject *source;
562
210
    PyObject *globals = Py_None;
563
210
    PyObject *locals = Py_None;
564
565
210
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
566
210
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
567
210
    if (!args) {
568
0
        goto exit;
569
0
    }
570
210
    source = args[0];
571
210
    if (!noptargs) {
572
0
        goto skip_optional_pos;
573
0
    }
574
210
    if (args[1]) {
575
210
        globals = args[1];
576
210
        if (!--noptargs) {
577
210
            goto skip_optional_pos;
578
210
        }
579
210
    }
580
0
    locals = args[2];
581
210
skip_optional_pos:
582
210
    return_value = builtin_eval_impl(module, source, globals, locals);
583
584
210
exit:
585
210
    return return_value;
586
210
}
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
8.22k
{
612
8.22k
    PyObject *return_value = NULL;
613
8.22k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
614
615
8.22k
    #define NUM_KEYWORDS 3
616
8.22k
    static struct {
617
8.22k
        PyGC_Head _this_is_not_used;
618
8.22k
        PyObject_VAR_HEAD
619
8.22k
        Py_hash_t ob_hash;
620
8.22k
        PyObject *ob_item[NUM_KEYWORDS];
621
8.22k
    } _kwtuple = {
622
8.22k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
623
8.22k
        .ob_hash = -1,
624
8.22k
        .ob_item = { &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(closure), },
625
8.22k
    };
626
8.22k
    #undef NUM_KEYWORDS
627
8.22k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
628
629
    #else  // !Py_BUILD_CORE
630
    #  define KWTUPLE NULL
631
    #endif  // !Py_BUILD_CORE
632
633
8.22k
    static const char * const _keywords[] = {"", "globals", "locals", "closure", NULL};
634
8.22k
    static _PyArg_Parser _parser = {
635
8.22k
        .keywords = _keywords,
636
8.22k
        .fname = "exec",
637
8.22k
        .kwtuple = KWTUPLE,
638
8.22k
    };
639
8.22k
    #undef KWTUPLE
640
8.22k
    PyObject *argsbuf[4];
641
8.22k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
642
8.22k
    PyObject *source;
643
8.22k
    PyObject *globals = Py_None;
644
8.22k
    PyObject *locals = Py_None;
645
8.22k
    PyObject *closure = NULL;
646
647
8.22k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
648
8.22k
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
649
8.22k
    if (!args) {
650
0
        goto exit;
651
0
    }
652
8.22k
    source = args[0];
653
8.22k
    if (!noptargs) {
654
0
        goto skip_optional_pos;
655
0
    }
656
8.22k
    if (args[1]) {
657
8.22k
        globals = args[1];
658
8.22k
        if (!--noptargs) {
659
8.08k
            goto skip_optional_pos;
660
8.08k
        }
661
8.22k
    }
662
134
    if (args[2]) {
663
134
        locals = args[2];
664
134
        if (!--noptargs) {
665
134
            goto skip_optional_pos;
666
134
        }
667
134
    }
668
8.22k
skip_optional_pos:
669
8.22k
    if (!noptargs) {
670
8.22k
        goto skip_optional_kwonly;
671
8.22k
    }
672
0
    closure = args[3];
673
8.22k
skip_optional_kwonly:
674
8.22k
    return_value = builtin_exec_impl(module, source, globals, locals, closure);
675
676
8.22k
exit:
677
8.22k
    return return_value;
678
8.22k
}
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
866
{
698
866
    return builtin_globals_impl(module);
699
866
}
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
13.4M
{
718
13.4M
    PyObject *return_value = NULL;
719
13.4M
    PyObject *obj;
720
13.4M
    PyObject *name;
721
722
13.4M
    if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
723
0
        goto exit;
724
0
    }
725
13.4M
    obj = args[0];
726
13.4M
    name = args[1];
727
13.4M
    return_value = builtin_hasattr_impl(module, obj, name);
728
729
13.4M
exit:
730
13.4M
    return return_value;
731
13.4M
}
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
44.0k
{
751
44.0k
    PyObject *return_value = NULL;
752
753
44.0k
    return_value = builtin_id_impl((PyModuleDef *)self, v);
754
755
44.0k
    return return_value;
756
44.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.62M
{
776
1.62M
    PyObject *return_value = NULL;
777
1.62M
    PyObject *obj;
778
1.62M
    PyObject *name;
779
1.62M
    PyObject *value;
780
781
1.62M
    if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) {
782
0
        goto exit;
783
0
    }
784
1.62M
    obj = args[0];
785
1.62M
    name = args[1];
786
1.62M
    value = args[2];
787
1.62M
    return_value = builtin_setattr_impl(module, obj, name, value);
788
789
1.62M
exit:
790
1.62M
    return return_value;
791
1.62M
}
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.19k
{
810
2.19k
    PyObject *return_value = NULL;
811
2.19k
    PyObject *obj;
812
2.19k
    PyObject *name;
813
814
2.19k
    if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
815
0
        goto exit;
816
0
    }
817
2.19k
    obj = args[0];
818
2.19k
    name = args[1];
819
2.19k
    return_value = builtin_delattr_impl(module, obj, name);
820
821
2.19k
exit:
822
2.19k
    return return_value;
823
2.19k
}
824
825
PyDoc_STRVAR(builtin_hash__doc__,
826
"hash($module, obj, /)\n"
827
"--\n"
828
"\n"
829
"Return the hash value for the given object.\n"
830
"\n"
831
"Two objects that compare equal must also have the same hash value, but the\n"
832
"reverse is not necessarily true.");
833
834
#define BUILTIN_HASH_METHODDEF    \
835
    {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
836
837
PyDoc_STRVAR(builtin_hex__doc__,
838
"hex($module, integer, /)\n"
839
"--\n"
840
"\n"
841
"Return the hexadecimal representation of an integer.\n"
842
"\n"
843
"   >>> hex(12648430)\n"
844
"   \'0xc0ffee\'");
845
846
#define BUILTIN_HEX_METHODDEF    \
847
    {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
848
849
PyDoc_STRVAR(builtin_aiter__doc__,
850
"aiter($module, async_iterable, /)\n"
851
"--\n"
852
"\n"
853
"Return an AsyncIterator for an AsyncIterable object.");
854
855
#define BUILTIN_AITER_METHODDEF    \
856
    {"aiter", (PyCFunction)builtin_aiter, METH_O, builtin_aiter__doc__},
857
858
PyDoc_STRVAR(builtin_anext__doc__,
859
"anext($module, async_iterator, default=<unrepresentable>, /)\n"
860
"--\n"
861
"\n"
862
"Return the next item from the async iterator.\n"
863
"\n"
864
"If default is given and the async iterator is exhausted,\n"
865
"it is returned instead of raising StopAsyncIteration.");
866
867
#define BUILTIN_ANEXT_METHODDEF    \
868
    {"anext", _PyCFunction_CAST(builtin_anext), METH_FASTCALL, builtin_anext__doc__},
869
870
static PyObject *
871
builtin_anext_impl(PyObject *module, PyObject *aiterator,
872
                   PyObject *default_value);
873
874
static PyObject *
875
builtin_anext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
876
0
{
877
0
    PyObject *return_value = NULL;
878
0
    PyObject *aiterator;
879
0
    PyObject *default_value = NULL;
880
881
0
    if (!_PyArg_CheckPositional("anext", nargs, 1, 2)) {
882
0
        goto exit;
883
0
    }
884
0
    aiterator = args[0];
885
0
    if (nargs < 2) {
886
0
        goto skip_optional;
887
0
    }
888
0
    default_value = args[1];
889
0
skip_optional:
890
0
    return_value = builtin_anext_impl(module, aiterator, default_value);
891
892
0
exit:
893
0
    return return_value;
894
0
}
895
896
PyDoc_STRVAR(builtin_len__doc__,
897
"len($module, obj, /)\n"
898
"--\n"
899
"\n"
900
"Return the number of items in a container.");
901
902
#define BUILTIN_LEN_METHODDEF    \
903
    {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
904
905
PyDoc_STRVAR(builtin_locals__doc__,
906
"locals($module, /)\n"
907
"--\n"
908
"\n"
909
"Return a dictionary containing the current scope\'s local variables.\n"
910
"\n"
911
"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
912
"the local scope and vice-versa is *implementation dependent* and not\n"
913
"covered by any backwards compatibility guarantees.");
914
915
#define BUILTIN_LOCALS_METHODDEF    \
916
    {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
917
918
static PyObject *
919
builtin_locals_impl(PyObject *module);
920
921
static PyObject *
922
builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
923
8
{
924
8
    return builtin_locals_impl(module);
925
8
}
926
927
PyDoc_STRVAR(builtin_oct__doc__,
928
"oct($module, integer, /)\n"
929
"--\n"
930
"\n"
931
"Return the octal representation of an integer.\n"
932
"\n"
933
"   >>> oct(342391)\n"
934
"   \'0o1234567\'");
935
936
#define BUILTIN_OCT_METHODDEF    \
937
    {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
938
939
PyDoc_STRVAR(builtin_ord__doc__,
940
"ord($module, character, /)\n"
941
"--\n"
942
"\n"
943
"Return the ordinal value of a character.\n"
944
"\n"
945
"If the argument is a one-character string, return the Unicode code\n"
946
"point of that character.\n"
947
"\n"
948
"If the argument is a bytes or bytearray object of length 1, return its\n"
949
"single byte value.");
950
951
#define BUILTIN_ORD_METHODDEF    \
952
    {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
953
954
PyDoc_STRVAR(builtin_pow__doc__,
955
"pow($module, /, base, exp, mod=None)\n"
956
"--\n"
957
"\n"
958
"Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments\n"
959
"\n"
960
"Some types, such as ints, are able to use a more efficient algorithm when\n"
961
"invoked using the three argument form.");
962
963
#define BUILTIN_POW_METHODDEF    \
964
    {"pow", _PyCFunction_CAST(builtin_pow), METH_FASTCALL|METH_KEYWORDS, builtin_pow__doc__},
965
966
static PyObject *
967
builtin_pow_impl(PyObject *module, PyObject *base, PyObject *exp,
968
                 PyObject *mod);
969
970
static PyObject *
971
builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
972
4
{
973
4
    PyObject *return_value = NULL;
974
4
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
975
976
4
    #define NUM_KEYWORDS 3
977
4
    static struct {
978
4
        PyGC_Head _this_is_not_used;
979
4
        PyObject_VAR_HEAD
980
4
        Py_hash_t ob_hash;
981
4
        PyObject *ob_item[NUM_KEYWORDS];
982
4
    } _kwtuple = {
983
4
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
984
4
        .ob_hash = -1,
985
4
        .ob_item = { &_Py_ID(base), &_Py_ID(exp), &_Py_ID(mod), },
986
4
    };
987
4
    #undef NUM_KEYWORDS
988
4
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
989
990
    #else  // !Py_BUILD_CORE
991
    #  define KWTUPLE NULL
992
    #endif  // !Py_BUILD_CORE
993
994
4
    static const char * const _keywords[] = {"base", "exp", "mod", NULL};
995
4
    static _PyArg_Parser _parser = {
996
4
        .keywords = _keywords,
997
4
        .fname = "pow",
998
4
        .kwtuple = KWTUPLE,
999
4
    };
1000
4
    #undef KWTUPLE
1001
4
    PyObject *argsbuf[3];
1002
4
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1003
4
    PyObject *base;
1004
4
    PyObject *exp;
1005
4
    PyObject *mod = Py_None;
1006
1007
4
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1008
4
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1009
4
    if (!args) {
1010
0
        goto exit;
1011
0
    }
1012
4
    base = args[0];
1013
4
    exp = args[1];
1014
4
    if (!noptargs) {
1015
0
        goto skip_optional_pos;
1016
0
    }
1017
4
    mod = args[2];
1018
4
skip_optional_pos:
1019
4
    return_value = builtin_pow_impl(module, base, exp, mod);
1020
1021
4
exit:
1022
4
    return return_value;
1023
4
}
1024
1025
PyDoc_STRVAR(builtin_print__doc__,
1026
"print($module, /, *objects, sep=\' \', end=\'\\n\', file=None, flush=False)\n"
1027
"--\n"
1028
"\n"
1029
"Prints the values to a stream, or to sys.stdout by default.\n"
1030
"\n"
1031
"  sep\n"
1032
"    string inserted between values, default a space.\n"
1033
"  end\n"
1034
"    string appended after the last value, default a newline.\n"
1035
"  file\n"
1036
"    a file-like object (stream); defaults to the current sys.stdout.\n"
1037
"  flush\n"
1038
"    whether to forcibly flush the stream.");
1039
1040
#define BUILTIN_PRINT_METHODDEF    \
1041
    {"print", _PyCFunction_CAST(builtin_print), METH_FASTCALL|METH_KEYWORDS, builtin_print__doc__},
1042
1043
static PyObject *
1044
builtin_print_impl(PyObject *module, PyObject * const *objects,
1045
                   Py_ssize_t objects_length, PyObject *sep, PyObject *end,
1046
                   PyObject *file, int flush);
1047
1048
static PyObject *
1049
builtin_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1050
0
{
1051
0
    PyObject *return_value = NULL;
1052
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1053
1054
0
    #define NUM_KEYWORDS 4
1055
0
    static struct {
1056
0
        PyGC_Head _this_is_not_used;
1057
0
        PyObject_VAR_HEAD
1058
0
        Py_hash_t ob_hash;
1059
0
        PyObject *ob_item[NUM_KEYWORDS];
1060
0
    } _kwtuple = {
1061
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1062
0
        .ob_hash = -1,
1063
0
        .ob_item = { &_Py_ID(sep), &_Py_ID(end), &_Py_ID(file), &_Py_ID(flush), },
1064
0
    };
1065
0
    #undef NUM_KEYWORDS
1066
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1067
1068
    #else  // !Py_BUILD_CORE
1069
    #  define KWTUPLE NULL
1070
    #endif  // !Py_BUILD_CORE
1071
1072
0
    static const char * const _keywords[] = {"sep", "end", "file", "flush", NULL};
1073
0
    static _PyArg_Parser _parser = {
1074
0
        .keywords = _keywords,
1075
0
        .fname = "print",
1076
0
        .kwtuple = KWTUPLE,
1077
0
    };
1078
0
    #undef KWTUPLE
1079
0
    PyObject *argsbuf[4];
1080
0
    PyObject * const *fastargs;
1081
0
    Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1082
0
    PyObject * const *objects;
1083
0
    Py_ssize_t objects_length;
1084
0
    PyObject *sep = Py_None;
1085
0
    PyObject *end = Py_None;
1086
0
    PyObject *file = Py_None;
1087
0
    int flush = 0;
1088
1089
0
    fastargs = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1090
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 1, argsbuf);
1091
0
    if (!fastargs) {
1092
0
        goto exit;
1093
0
    }
1094
0
    if (!noptargs) {
1095
0
        goto skip_optional_kwonly;
1096
0
    }
1097
0
    if (fastargs[0]) {
1098
0
        sep = fastargs[0];
1099
0
        if (!--noptargs) {
1100
0
            goto skip_optional_kwonly;
1101
0
        }
1102
0
    }
1103
0
    if (fastargs[1]) {
1104
0
        end = fastargs[1];
1105
0
        if (!--noptargs) {
1106
0
            goto skip_optional_kwonly;
1107
0
        }
1108
0
    }
1109
0
    if (fastargs[2]) {
1110
0
        file = fastargs[2];
1111
0
        if (!--noptargs) {
1112
0
            goto skip_optional_kwonly;
1113
0
        }
1114
0
    }
1115
0
    flush = PyObject_IsTrue(fastargs[3]);
1116
0
    if (flush < 0) {
1117
0
        goto exit;
1118
0
    }
1119
0
skip_optional_kwonly:
1120
0
    objects = args;
1121
0
    objects_length = nargs;
1122
0
    return_value = builtin_print_impl(module, objects, objects_length, sep, end, file, flush);
1123
1124
0
exit:
1125
0
    return return_value;
1126
0
}
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
builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1148
0
{
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
0
    }
1155
0
    if (nargs < 1) {
1156
0
        goto skip_optional;
1157
0
    }
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
0
}
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
builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1194
0
{
1195
0
    PyObject *return_value = NULL;
1196
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1197
1198
0
    #define NUM_KEYWORDS 2
1199
0
    static struct {
1200
0
        PyGC_Head _this_is_not_used;
1201
0
        PyObject_VAR_HEAD
1202
0
        Py_hash_t ob_hash;
1203
0
        PyObject *ob_item[NUM_KEYWORDS];
1204
0
    } _kwtuple = {
1205
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1206
0
        .ob_hash = -1,
1207
0
        .ob_item = { &_Py_ID(number), &_Py_ID(ndigits), },
1208
0
    };
1209
0
    #undef NUM_KEYWORDS
1210
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1211
1212
    #else  // !Py_BUILD_CORE
1213
    #  define KWTUPLE NULL
1214
    #endif  // !Py_BUILD_CORE
1215
1216
0
    static const char * const _keywords[] = {"number", "ndigits", NULL};
1217
0
    static _PyArg_Parser _parser = {
1218
0
        .keywords = _keywords,
1219
0
        .fname = "round",
1220
0
        .kwtuple = KWTUPLE,
1221
0
    };
1222
0
    #undef KWTUPLE
1223
0
    PyObject *argsbuf[2];
1224
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1225
0
    PyObject *number;
1226
0
    PyObject *ndigits = Py_None;
1227
1228
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1229
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1230
0
    if (!args) {
1231
0
        goto exit;
1232
0
    }
1233
0
    number = args[0];
1234
0
    if (!noptargs) {
1235
0
        goto skip_optional_pos;
1236
0
    }
1237
0
    ndigits = args[1];
1238
0
skip_optional_pos:
1239
0
    return_value = builtin_round_impl(module, number, ndigits);
1240
1241
0
exit:
1242
0
    return return_value;
1243
0
}
1244
1245
PyDoc_STRVAR(builtin_sum__doc__,
1246
"sum($module, iterable, /, start=0)\n"
1247
"--\n"
1248
"\n"
1249
"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
1250
"\n"
1251
"When the iterable is empty, return the start value.\n"
1252
"This function is intended specifically for use with numeric values and may\n"
1253
"reject non-numeric types.");
1254
1255
#define BUILTIN_SUM_METHODDEF    \
1256
    {"sum", _PyCFunction_CAST(builtin_sum), METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__},
1257
1258
static PyObject *
1259
builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
1260
1261
static PyObject *
1262
builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1263
9.88M
{
1264
9.88M
    PyObject *return_value = NULL;
1265
9.88M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1266
1267
9.88M
    #define NUM_KEYWORDS 1
1268
9.88M
    static struct {
1269
9.88M
        PyGC_Head _this_is_not_used;
1270
9.88M
        PyObject_VAR_HEAD
1271
9.88M
        Py_hash_t ob_hash;
1272
9.88M
        PyObject *ob_item[NUM_KEYWORDS];
1273
9.88M
    } _kwtuple = {
1274
9.88M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1275
9.88M
        .ob_hash = -1,
1276
9.88M
        .ob_item = { &_Py_ID(start), },
1277
9.88M
    };
1278
9.88M
    #undef NUM_KEYWORDS
1279
9.88M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1280
1281
    #else  // !Py_BUILD_CORE
1282
    #  define KWTUPLE NULL
1283
    #endif  // !Py_BUILD_CORE
1284
1285
9.88M
    static const char * const _keywords[] = {"", "start", NULL};
1286
9.88M
    static _PyArg_Parser _parser = {
1287
9.88M
        .keywords = _keywords,
1288
9.88M
        .fname = "sum",
1289
9.88M
        .kwtuple = KWTUPLE,
1290
9.88M
    };
1291
9.88M
    #undef KWTUPLE
1292
9.88M
    PyObject *argsbuf[2];
1293
9.88M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1294
9.88M
    PyObject *iterable;
1295
9.88M
    PyObject *start = NULL;
1296
1297
9.88M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1298
9.88M
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1299
9.88M
    if (!args) {
1300
0
        goto exit;
1301
0
    }
1302
9.88M
    iterable = args[0];
1303
9.88M
    if (!noptargs) {
1304
700k
        goto skip_optional_pos;
1305
700k
    }
1306
9.18M
    start = args[1];
1307
9.88M
skip_optional_pos:
1308
9.88M
    return_value = builtin_sum_impl(module, iterable, start);
1309
1310
9.88M
exit:
1311
9.88M
    return return_value;
1312
9.88M
}
1313
1314
PyDoc_STRVAR(builtin_isinstance__doc__,
1315
"isinstance($module, obj, class_or_tuple, /)\n"
1316
"--\n"
1317
"\n"
1318
"Return whether an object is an instance of a class or of a subclass thereof.\n"
1319
"\n"
1320
"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
1321
"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
1322
"or ...`` etc.");
1323
1324
#define BUILTIN_ISINSTANCE_METHODDEF    \
1325
    {"isinstance", _PyCFunction_CAST(builtin_isinstance), METH_FASTCALL, builtin_isinstance__doc__},
1326
1327
static PyObject *
1328
builtin_isinstance_impl(PyObject *module, PyObject *obj,
1329
                        PyObject *class_or_tuple);
1330
1331
static PyObject *
1332
builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1333
2.56k
{
1334
2.56k
    PyObject *return_value = NULL;
1335
2.56k
    PyObject *obj;
1336
2.56k
    PyObject *class_or_tuple;
1337
1338
2.56k
    if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
1339
0
        goto exit;
1340
0
    }
1341
2.56k
    obj = args[0];
1342
2.56k
    class_or_tuple = args[1];
1343
2.56k
    return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
1344
1345
2.56k
exit:
1346
2.56k
    return return_value;
1347
2.56k
}
1348
1349
PyDoc_STRVAR(builtin_issubclass__doc__,
1350
"issubclass($module, cls, class_or_tuple, /)\n"
1351
"--\n"
1352
"\n"
1353
"Return whether \'cls\' is derived from another class or is the same class.\n"
1354
"\n"
1355
"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
1356
"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
1357
"or ...``.");
1358
1359
#define BUILTIN_ISSUBCLASS_METHODDEF    \
1360
    {"issubclass", _PyCFunction_CAST(builtin_issubclass), METH_FASTCALL, builtin_issubclass__doc__},
1361
1362
static PyObject *
1363
builtin_issubclass_impl(PyObject *module, PyObject *cls,
1364
                        PyObject *class_or_tuple);
1365
1366
static PyObject *
1367
builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1368
16.5k
{
1369
16.5k
    PyObject *return_value = NULL;
1370
16.5k
    PyObject *cls;
1371
16.5k
    PyObject *class_or_tuple;
1372
1373
16.5k
    if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
1374
0
        goto exit;
1375
0
    }
1376
16.5k
    cls = args[0];
1377
16.5k
    class_or_tuple = args[1];
1378
16.5k
    return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
1379
1380
16.5k
exit:
1381
16.5k
    return return_value;
1382
16.5k
}
1383
/*[clinic end generated code: output=1c3327da8885bb8e input=a9049054013a1b77]*/