Coverage Report

Created: 2025-08-26 06:26

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