Coverage Report

Created: 2025-10-13 06:15

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