Coverage Report

Created: 2026-04-12 06:54

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
273k
{
42
273k
    PyObject *return_value = NULL;
43
273k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
44
45
273k
    #define NUM_KEYWORDS 5
46
273k
    static struct {
47
273k
        PyGC_Head _this_is_not_used;
48
273k
        PyObject_VAR_HEAD
49
273k
        Py_hash_t ob_hash;
50
273k
        PyObject *ob_item[NUM_KEYWORDS];
51
273k
    } _kwtuple = {
52
273k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
53
273k
        .ob_hash = -1,
54
273k
        .ob_item = { &_Py_ID(name), &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(fromlist), &_Py_ID(level), },
55
273k
    };
56
273k
    #undef NUM_KEYWORDS
57
273k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
58
59
    #else  // !Py_BUILD_CORE
60
    #  define KWTUPLE NULL
61
    #endif  // !Py_BUILD_CORE
62
63
273k
    static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL};
64
273k
    static _PyArg_Parser _parser = {
65
273k
        .keywords = _keywords,
66
273k
        .fname = "__import__",
67
273k
        .kwtuple = KWTUPLE,
68
273k
    };
69
273k
    #undef KWTUPLE
70
273k
    PyObject *argsbuf[5];
71
273k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
72
273k
    PyObject *name;
73
273k
    PyObject *globals = NULL;
74
273k
    PyObject *locals = NULL;
75
273k
    PyObject *fromlist = NULL;
76
273k
    int level = 0;
77
78
273k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
79
273k
            /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
80
273k
    if (!args) {
81
0
        goto exit;
82
0
    }
83
273k
    name = args[0];
84
273k
    if (!noptargs) {
85
854
        goto skip_optional_pos;
86
854
    }
87
273k
    if (args[1]) {
88
269k
        globals = args[1];
89
269k
        if (!--noptargs) {
90
0
            goto skip_optional_pos;
91
0
        }
92
269k
    }
93
273k
    if (args[2]) {
94
269k
        locals = args[2];
95
269k
        if (!--noptargs) {
96
0
            goto skip_optional_pos;
97
0
        }
98
269k
    }
99
273k
    if (args[3]) {
100
273k
        fromlist = args[3];
101
273k
        if (!--noptargs) {
102
0
            goto skip_optional_pos;
103
0
        }
104
273k
    }
105
273k
    level = PyLong_AsInt(args[4]);
106
273k
    if (level == -1 && PyErr_Occurred()) {
107
0
        goto exit;
108
0
    }
109
273k
skip_optional_pos:
110
273k
    return_value = builtin___import___impl(module, name, globals, locals, fromlist, level);
111
112
273k
exit:
113
273k
    return return_value;
114
273k
}
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
100k
        flags = PyLong_AsInt(args[3]);
430
100k
        if (flags == -1 && PyErr_Occurred()) {
431
0
            goto exit;
432
0
        }
433
100k
        if (!--noptargs) {
434
0
            goto skip_optional_pos;
435
0
        }
436
100k
    }
437
101k
    if (args[4]) {
438
170
        dont_inherit = PyObject_IsTrue(args[4]);
439
170
        if (dont_inherit < 0) {
440
0
            goto exit;
441
0
        }
442
170
        if (!--noptargs) {
443
0
            goto skip_optional_pos;
444
0
        }
445
170
    }
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
170
            goto skip_optional_kwonly;
463
170
        }
464
101k
    }
465
100k
    feature_version = PyLong_AsInt(args[7]);
466
100k
    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
957k
{
494
957k
    PyObject *return_value = NULL;
495
957k
    PyObject *x;
496
957k
    PyObject *y;
497
498
957k
    if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
499
0
        goto exit;
500
0
    }
501
957k
    x = args[0];
502
957k
    y = args[1];
503
957k
    return_value = builtin_divmod_impl(module, x, y);
504
505
957k
exit:
506
957k
    return return_value;
507
957k
}
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
219
{
531
219
    PyObject *return_value = NULL;
532
219
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
533
534
219
    #define NUM_KEYWORDS 2
535
219
    static struct {
536
219
        PyGC_Head _this_is_not_used;
537
219
        PyObject_VAR_HEAD
538
219
        Py_hash_t ob_hash;
539
219
        PyObject *ob_item[NUM_KEYWORDS];
540
219
    } _kwtuple = {
541
219
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
542
219
        .ob_hash = -1,
543
219
        .ob_item = { &_Py_ID(globals), &_Py_ID(locals), },
544
219
    };
545
219
    #undef NUM_KEYWORDS
546
219
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
547
548
    #else  // !Py_BUILD_CORE
549
    #  define KWTUPLE NULL
550
    #endif  // !Py_BUILD_CORE
551
552
219
    static const char * const _keywords[] = {"", "globals", "locals", NULL};
553
219
    static _PyArg_Parser _parser = {
554
219
        .keywords = _keywords,
555
219
        .fname = "eval",
556
219
        .kwtuple = KWTUPLE,
557
219
    };
558
219
    #undef KWTUPLE
559
219
    PyObject *argsbuf[3];
560
219
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
561
219
    PyObject *source;
562
219
    PyObject *globals = Py_None;
563
219
    PyObject *locals = Py_None;
564
565
219
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
566
219
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
567
219
    if (!args) {
568
0
        goto exit;
569
0
    }
570
219
    source = args[0];
571
219
    if (!noptargs) {
572
0
        goto skip_optional_pos;
573
0
    }
574
219
    if (args[1]) {
575
219
        globals = args[1];
576
219
        if (!--noptargs) {
577
219
            goto skip_optional_pos;
578
219
        }
579
219
    }
580
0
    locals = args[2];
581
219
skip_optional_pos:
582
219
    return_value = builtin_eval_impl(module, source, globals, locals);
583
584
219
exit:
585
219
    return return_value;
586
219
}
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
6.95k
{
612
6.95k
    PyObject *return_value = NULL;
613
6.95k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
614
615
6.95k
    #define NUM_KEYWORDS 3
616
6.95k
    static struct {
617
6.95k
        PyGC_Head _this_is_not_used;
618
6.95k
        PyObject_VAR_HEAD
619
6.95k
        Py_hash_t ob_hash;
620
6.95k
        PyObject *ob_item[NUM_KEYWORDS];
621
6.95k
    } _kwtuple = {
622
6.95k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
623
6.95k
        .ob_hash = -1,
624
6.95k
        .ob_item = { &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(closure), },
625
6.95k
    };
626
6.95k
    #undef NUM_KEYWORDS
627
6.95k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
628
629
    #else  // !Py_BUILD_CORE
630
    #  define KWTUPLE NULL
631
    #endif  // !Py_BUILD_CORE
632
633
6.95k
    static const char * const _keywords[] = {"", "globals", "locals", "closure", NULL};
634
6.95k
    static _PyArg_Parser _parser = {
635
6.95k
        .keywords = _keywords,
636
6.95k
        .fname = "exec",
637
6.95k
        .kwtuple = KWTUPLE,
638
6.95k
    };
639
6.95k
    #undef KWTUPLE
640
6.95k
    PyObject *argsbuf[4];
641
6.95k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
642
6.95k
    PyObject *source;
643
6.95k
    PyObject *globals = Py_None;
644
6.95k
    PyObject *locals = Py_None;
645
6.95k
    PyObject *closure = NULL;
646
647
6.95k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
648
6.95k
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
649
6.95k
    if (!args) {
650
0
        goto exit;
651
0
    }
652
6.95k
    source = args[0];
653
6.95k
    if (!noptargs) {
654
0
        goto skip_optional_pos;
655
0
    }
656
6.95k
    if (args[1]) {
657
6.95k
        globals = args[1];
658
6.95k
        if (!--noptargs) {
659
6.80k
            goto skip_optional_pos;
660
6.80k
        }
661
6.95k
    }
662
152
    if (args[2]) {
663
152
        locals = args[2];
664
152
        if (!--noptargs) {
665
152
            goto skip_optional_pos;
666
152
        }
667
152
    }
668
6.95k
skip_optional_pos:
669
6.95k
    if (!noptargs) {
670
6.95k
        goto skip_optional_kwonly;
671
6.95k
    }
672
0
    closure = args[3];
673
6.95k
skip_optional_kwonly:
674
6.95k
    return_value = builtin_exec_impl(module, source, globals, locals, closure);
675
676
6.95k
exit:
677
6.95k
    return return_value;
678
6.95k
}
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
879
{
698
879
    return builtin_globals_impl(module);
699
879
}
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.7M
{
718
10.7M
    PyObject *return_value = NULL;
719
10.7M
    PyObject *obj;
720
10.7M
    PyObject *name;
721
722
10.7M
    if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
723
0
        goto exit;
724
0
    }
725
10.7M
    obj = args[0];
726
10.7M
    name = args[1];
727
10.7M
    return_value = builtin_hasattr_impl(module, obj, name);
728
729
10.7M
exit:
730
10.7M
    return return_value;
731
10.7M
}
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
24.5k
{
751
24.5k
    PyObject *return_value = NULL;
752
753
24.5k
    return_value = builtin_id_impl((PyModuleDef *)self, v);
754
755
24.5k
    return return_value;
756
24.5k
}
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.31k
{
810
2.31k
    PyObject *return_value = NULL;
811
2.31k
    PyObject *obj;
812
2.31k
    PyObject *name;
813
814
2.31k
    if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
815
0
        goto exit;
816
0
    }
817
2.31k
    obj = args[0];
818
2.31k
    name = args[1];
819
2.31k
    return_value = builtin_delattr_impl(module, obj, name);
820
821
2.31k
exit:
822
2.31k
    return return_value;
823
2.31k
}
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
13.0M
{
1264
13.0M
    PyObject *return_value = NULL;
1265
13.0M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1266
1267
13.0M
    #define NUM_KEYWORDS 1
1268
13.0M
    static struct {
1269
13.0M
        PyGC_Head _this_is_not_used;
1270
13.0M
        PyObject_VAR_HEAD
1271
13.0M
        Py_hash_t ob_hash;
1272
13.0M
        PyObject *ob_item[NUM_KEYWORDS];
1273
13.0M
    } _kwtuple = {
1274
13.0M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1275
13.0M
        .ob_hash = -1,
1276
13.0M
        .ob_item = { &_Py_ID(start), },
1277
13.0M
    };
1278
13.0M
    #undef NUM_KEYWORDS
1279
13.0M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1280
1281
    #else  // !Py_BUILD_CORE
1282
    #  define KWTUPLE NULL
1283
    #endif  // !Py_BUILD_CORE
1284
1285
13.0M
    static const char * const _keywords[] = {"", "start", NULL};
1286
13.0M
    static _PyArg_Parser _parser = {
1287
13.0M
        .keywords = _keywords,
1288
13.0M
        .fname = "sum",
1289
13.0M
        .kwtuple = KWTUPLE,
1290
13.0M
    };
1291
13.0M
    #undef KWTUPLE
1292
13.0M
    PyObject *argsbuf[2];
1293
13.0M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1294
13.0M
    PyObject *iterable;
1295
13.0M
    PyObject *start = NULL;
1296
1297
13.0M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1298
13.0M
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1299
13.0M
    if (!args) {
1300
0
        goto exit;
1301
0
    }
1302
13.0M
    iterable = args[0];
1303
13.0M
    if (!noptargs) {
1304
4.10M
        goto skip_optional_pos;
1305
4.10M
    }
1306
8.92M
    start = args[1];
1307
13.0M
skip_optional_pos:
1308
13.0M
    return_value = builtin_sum_impl(module, iterable, start);
1309
1310
13.0M
exit:
1311
13.0M
    return return_value;
1312
13.0M
}
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.60k
{
1334
2.60k
    PyObject *return_value = NULL;
1335
2.60k
    PyObject *obj;
1336
2.60k
    PyObject *class_or_tuple;
1337
1338
2.60k
    if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
1339
0
        goto exit;
1340
0
    }
1341
2.60k
    obj = args[0];
1342
2.60k
    class_or_tuple = args[1];
1343
2.60k
    return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
1344
1345
2.60k
exit:
1346
2.60k
    return return_value;
1347
2.60k
}
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
19.3k
{
1369
19.3k
    PyObject *return_value = NULL;
1370
19.3k
    PyObject *cls;
1371
19.3k
    PyObject *class_or_tuple;
1372
1373
19.3k
    if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
1374
0
        goto exit;
1375
0
    }
1376
19.3k
    cls = args[0];
1377
19.3k
    class_or_tuple = args[1];
1378
19.3k
    return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
1379
1380
19.3k
exit:
1381
19.3k
    return return_value;
1382
19.3k
}
1383
/*[clinic end generated code: output=1c3327da8885bb8e input=a9049054013a1b77]*/