Coverage Report

Created: 2026-02-09 07:07

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