Coverage Report

Created: 2025-08-29 07:13

/src/cpython3/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
261k
{
42
261k
    PyObject *return_value = NULL;
43
261k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
44
45
261k
    #define NUM_KEYWORDS 5
46
261k
    static struct {
47
261k
        PyGC_Head _this_is_not_used;
48
261k
        PyObject_VAR_HEAD
49
261k
        Py_hash_t ob_hash;
50
261k
        PyObject *ob_item[NUM_KEYWORDS];
51
261k
    } _kwtuple = {
52
261k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
53
261k
        .ob_hash = -1,
54
261k
        .ob_item = { &_Py_ID(name), &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(fromlist), &_Py_ID(level), },
55
261k
    };
56
261k
    #undef NUM_KEYWORDS
57
261k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
58
59
    #else  // !Py_BUILD_CORE
60
    #  define KWTUPLE NULL
61
    #endif  // !Py_BUILD_CORE
62
63
261k
    static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL};
64
261k
    static _PyArg_Parser _parser = {
65
261k
        .keywords = _keywords,
66
261k
        .fname = "__import__",
67
261k
        .kwtuple = KWTUPLE,
68
261k
    };
69
261k
    #undef KWTUPLE
70
261k
    PyObject *argsbuf[5];
71
261k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
72
261k
    PyObject *name;
73
261k
    PyObject *globals = NULL;
74
261k
    PyObject *locals = NULL;
75
261k
    PyObject *fromlist = NULL;
76
261k
    int level = 0;
77
78
261k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
79
261k
            /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
80
261k
    if (!args) {
81
0
        goto exit;
82
0
    }
83
261k
    name = args[0];
84
261k
    if (!noptargs) {
85
92
        goto skip_optional_pos;
86
92
    }
87
261k
    if (args[1]) {
88
260k
        globals = args[1];
89
260k
        if (!--noptargs) {
90
0
            goto skip_optional_pos;
91
0
        }
92
260k
    }
93
261k
    if (args[2]) {
94
260k
        locals = args[2];
95
260k
        if (!--noptargs) {
96
0
            goto skip_optional_pos;
97
0
        }
98
260k
    }
99
261k
    if (args[3]) {
100
261k
        fromlist = args[3];
101
261k
        if (!--noptargs) {
102
0
            goto skip_optional_pos;
103
0
        }
104
261k
    }
105
261k
    level = PyLong_AsInt(args[4]);
106
261k
    if (level == -1 && PyErr_Occurred()) {
107
0
        goto exit;
108
0
    }
109
261k
skip_optional_pos:
110
261k
    return_value = builtin___import___impl(module, name, globals, locals, fromlist, level);
111
112
261k
exit:
113
261k
    return return_value;
114
261k
}
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
21
{
268
21
    PyObject *return_value = NULL;
269
21
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
270
271
21
    #define NUM_KEYWORDS 7
272
21
    static struct {
273
21
        PyGC_Head _this_is_not_used;
274
21
        PyObject_VAR_HEAD
275
21
        Py_hash_t ob_hash;
276
21
        PyObject *ob_item[NUM_KEYWORDS];
277
21
    } _kwtuple = {
278
21
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
279
21
        .ob_hash = -1,
280
21
        .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
21
    };
282
21
    #undef NUM_KEYWORDS
283
21
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
284
285
    #else  // !Py_BUILD_CORE
286
    #  define KWTUPLE NULL
287
    #endif  // !Py_BUILD_CORE
288
289
21
    static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "_feature_version", NULL};
290
21
    static _PyArg_Parser _parser = {
291
21
        .keywords = _keywords,
292
21
        .fname = "compile",
293
21
        .kwtuple = KWTUPLE,
294
21
    };
295
21
    #undef KWTUPLE
296
21
    PyObject *argsbuf[7];
297
21
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
298
21
    PyObject *source;
299
21
    PyObject *filename;
300
21
    const char *mode;
301
21
    int flags = 0;
302
21
    int dont_inherit = 0;
303
21
    int optimize = -1;
304
21
    int feature_version = -1;
305
306
21
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
307
21
            /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
308
21
    if (!args) {
309
0
        goto exit;
310
0
    }
311
21
    source = args[0];
312
21
    if (!PyUnicode_FSDecoder(args[1], &filename)) {
313
0
        goto exit;
314
0
    }
315
21
    if (!PyUnicode_Check(args[2])) {
316
0
        _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]);
317
0
        goto exit;
318
0
    }
319
21
    Py_ssize_t mode_length;
320
21
    mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length);
321
21
    if (mode == NULL) {
322
0
        goto exit;
323
0
    }
324
21
    if (strlen(mode) != (size_t)mode_length) {
325
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
326
0
        goto exit;
327
0
    }
328
21
    if (!noptargs) {
329
0
        goto skip_optional_pos;
330
0
    }
331
21
    if (args[3]) {
332
21
        flags = PyLong_AsInt(args[3]);
333
21
        if (flags == -1 && PyErr_Occurred()) {
334
0
            goto exit;
335
0
        }
336
21
        if (!--noptargs) {
337
0
            goto skip_optional_pos;
338
0
        }
339
21
    }
340
21
    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
21
    if (args[5]) {
350
21
        optimize = PyLong_AsInt(args[5]);
351
21
        if (optimize == -1 && PyErr_Occurred()) {
352
0
            goto exit;
353
0
        }
354
21
        if (!--noptargs) {
355
0
            goto skip_optional_pos;
356
0
        }
357
21
    }
358
21
skip_optional_pos:
359
21
    if (!noptargs) {
360
0
        goto skip_optional_kwonly;
361
0
    }
362
21
    feature_version = PyLong_AsInt(args[6]);
363
21
    if (feature_version == -1 && PyErr_Occurred()) {
364
0
        goto exit;
365
0
    }
366
21
skip_optional_kwonly:
367
21
    return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version);
368
369
21
exit:
370
21
    return return_value;
371
21
}
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
674
{
388
674
    PyObject *return_value = NULL;
389
674
    PyObject *x;
390
674
    PyObject *y;
391
392
674
    if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
393
0
        goto exit;
394
0
    }
395
674
    x = args[0];
396
674
    y = args[1];
397
674
    return_value = builtin_divmod_impl(module, x, y);
398
399
674
exit:
400
674
    return return_value;
401
674
}
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
14
{
425
14
    PyObject *return_value = NULL;
426
14
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
427
428
14
    #define NUM_KEYWORDS 2
429
14
    static struct {
430
14
        PyGC_Head _this_is_not_used;
431
14
        PyObject_VAR_HEAD
432
14
        Py_hash_t ob_hash;
433
14
        PyObject *ob_item[NUM_KEYWORDS];
434
14
    } _kwtuple = {
435
14
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
436
14
        .ob_hash = -1,
437
14
        .ob_item = { &_Py_ID(globals), &_Py_ID(locals), },
438
14
    };
439
14
    #undef NUM_KEYWORDS
440
14
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
441
442
    #else  // !Py_BUILD_CORE
443
    #  define KWTUPLE NULL
444
    #endif  // !Py_BUILD_CORE
445
446
14
    static const char * const _keywords[] = {"", "globals", "locals", NULL};
447
14
    static _PyArg_Parser _parser = {
448
14
        .keywords = _keywords,
449
14
        .fname = "eval",
450
14
        .kwtuple = KWTUPLE,
451
14
    };
452
14
    #undef KWTUPLE
453
14
    PyObject *argsbuf[3];
454
14
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
455
14
    PyObject *source;
456
14
    PyObject *globals = Py_None;
457
14
    PyObject *locals = Py_None;
458
459
14
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
460
14
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
461
14
    if (!args) {
462
0
        goto exit;
463
0
    }
464
14
    source = args[0];
465
14
    if (!noptargs) {
466
0
        goto skip_optional_pos;
467
0
    }
468
14
    if (args[1]) {
469
14
        globals = args[1];
470
14
        if (!--noptargs) {
471
14
            goto skip_optional_pos;
472
14
        }
473
14
    }
474
0
    locals = args[2];
475
14
skip_optional_pos:
476
14
    return_value = builtin_eval_impl(module, source, globals, locals);
477
478
14
exit:
479
14
    return return_value;
480
14
}
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
590
{
506
590
    PyObject *return_value = NULL;
507
590
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
508
509
590
    #define NUM_KEYWORDS 3
510
590
    static struct {
511
590
        PyGC_Head _this_is_not_used;
512
590
        PyObject_VAR_HEAD
513
590
        Py_hash_t ob_hash;
514
590
        PyObject *ob_item[NUM_KEYWORDS];
515
590
    } _kwtuple = {
516
590
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
517
590
        .ob_hash = -1,
518
590
        .ob_item = { &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(closure), },
519
590
    };
520
590
    #undef NUM_KEYWORDS
521
590
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
522
523
    #else  // !Py_BUILD_CORE
524
    #  define KWTUPLE NULL
525
    #endif  // !Py_BUILD_CORE
526
527
590
    static const char * const _keywords[] = {"", "globals", "locals", "closure", NULL};
528
590
    static _PyArg_Parser _parser = {
529
590
        .keywords = _keywords,
530
590
        .fname = "exec",
531
590
        .kwtuple = KWTUPLE,
532
590
    };
533
590
    #undef KWTUPLE
534
590
    PyObject *argsbuf[4];
535
590
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
536
590
    PyObject *source;
537
590
    PyObject *globals = Py_None;
538
590
    PyObject *locals = Py_None;
539
590
    PyObject *closure = NULL;
540
541
590
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
542
590
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
543
590
    if (!args) {
544
0
        goto exit;
545
0
    }
546
590
    source = args[0];
547
590
    if (!noptargs) {
548
0
        goto skip_optional_pos;
549
0
    }
550
590
    if (args[1]) {
551
590
        globals = args[1];
552
590
        if (!--noptargs) {
553
590
            goto skip_optional_pos;
554
590
        }
555
590
    }
556
0
    if (args[2]) {
557
0
        locals = args[2];
558
0
        if (!--noptargs) {
559
0
            goto skip_optional_pos;
560
0
        }
561
0
    }
562
590
skip_optional_pos:
563
590
    if (!noptargs) {
564
590
        goto skip_optional_kwonly;
565
590
    }
566
0
    closure = args[3];
567
590
skip_optional_kwonly:
568
590
    return_value = builtin_exec_impl(module, source, globals, locals, closure);
569
570
590
exit:
571
590
    return return_value;
572
590
}
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
326
{
592
326
    return builtin_globals_impl(module);
593
326
}
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
3.80k
{
612
3.80k
    PyObject *return_value = NULL;
613
3.80k
    PyObject *obj;
614
3.80k
    PyObject *name;
615
616
3.80k
    if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
617
0
        goto exit;
618
0
    }
619
3.80k
    obj = args[0];
620
3.80k
    name = args[1];
621
3.80k
    return_value = builtin_hasattr_impl(module, obj, name);
622
623
3.80k
exit:
624
3.80k
    return return_value;
625
3.80k
}
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
0
{
645
0
    PyObject *return_value = NULL;
646
647
0
    return_value = builtin_id_impl((PyModuleDef *)self, v);
648
649
0
    return return_value;
650
0
}
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
1.60k
{
670
1.60k
    PyObject *return_value = NULL;
671
1.60k
    PyObject *obj;
672
1.60k
    PyObject *name;
673
1.60k
    PyObject *value;
674
675
1.60k
    if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) {
676
0
        goto exit;
677
0
    }
678
1.60k
    obj = args[0];
679
1.60k
    name = args[1];
680
1.60k
    value = args[2];
681
1.60k
    return_value = builtin_setattr_impl(module, obj, name, value);
682
683
1.60k
exit:
684
1.60k
    return return_value;
685
1.60k
}
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
252
{
704
252
    PyObject *return_value = NULL;
705
252
    PyObject *obj;
706
252
    PyObject *name;
707
708
252
    if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
709
0
        goto exit;
710
0
    }
711
252
    obj = args[0];
712
252
    name = args[1];
713
252
    return_value = builtin_delattr_impl(module, obj, name);
714
715
252
exit:
716
252
    return return_value;
717
252
}
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
4
{
867
4
    PyObject *return_value = NULL;
868
4
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
869
870
4
    #define NUM_KEYWORDS 3
871
4
    static struct {
872
4
        PyGC_Head _this_is_not_used;
873
4
        PyObject_VAR_HEAD
874
4
        Py_hash_t ob_hash;
875
4
        PyObject *ob_item[NUM_KEYWORDS];
876
4
    } _kwtuple = {
877
4
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
878
4
        .ob_hash = -1,
879
4
        .ob_item = { &_Py_ID(base), &_Py_ID(exp), &_Py_ID(mod), },
880
4
    };
881
4
    #undef NUM_KEYWORDS
882
4
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
883
884
    #else  // !Py_BUILD_CORE
885
    #  define KWTUPLE NULL
886
    #endif  // !Py_BUILD_CORE
887
888
4
    static const char * const _keywords[] = {"base", "exp", "mod", NULL};
889
4
    static _PyArg_Parser _parser = {
890
4
        .keywords = _keywords,
891
4
        .fname = "pow",
892
4
        .kwtuple = KWTUPLE,
893
4
    };
894
4
    #undef KWTUPLE
895
4
    PyObject *argsbuf[3];
896
4
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
897
4
    PyObject *base;
898
4
    PyObject *exp;
899
4
    PyObject *mod = Py_None;
900
901
4
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
902
4
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
903
4
    if (!args) {
904
0
        goto exit;
905
0
    }
906
4
    base = args[0];
907
4
    exp = args[1];
908
4
    if (!noptargs) {
909
0
        goto skip_optional_pos;
910
0
    }
911
4
    mod = args[2];
912
4
skip_optional_pos:
913
4
    return_value = builtin_pow_impl(module, base, exp, mod);
914
915
4
exit:
916
4
    return return_value;
917
4
}
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
719
{
1158
719
    PyObject *return_value = NULL;
1159
719
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1160
1161
719
    #define NUM_KEYWORDS 1
1162
719
    static struct {
1163
719
        PyGC_Head _this_is_not_used;
1164
719
        PyObject_VAR_HEAD
1165
719
        Py_hash_t ob_hash;
1166
719
        PyObject *ob_item[NUM_KEYWORDS];
1167
719
    } _kwtuple = {
1168
719
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1169
719
        .ob_hash = -1,
1170
719
        .ob_item = { &_Py_ID(start), },
1171
719
    };
1172
719
    #undef NUM_KEYWORDS
1173
719
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1174
1175
    #else  // !Py_BUILD_CORE
1176
    #  define KWTUPLE NULL
1177
    #endif  // !Py_BUILD_CORE
1178
1179
719
    static const char * const _keywords[] = {"", "start", NULL};
1180
719
    static _PyArg_Parser _parser = {
1181
719
        .keywords = _keywords,
1182
719
        .fname = "sum",
1183
719
        .kwtuple = KWTUPLE,
1184
719
    };
1185
719
    #undef KWTUPLE
1186
719
    PyObject *argsbuf[2];
1187
719
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1188
719
    PyObject *iterable;
1189
719
    PyObject *start = NULL;
1190
1191
719
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1192
719
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1193
719
    if (!args) {
1194
0
        goto exit;
1195
0
    }
1196
719
    iterable = args[0];
1197
719
    if (!noptargs) {
1198
719
        goto skip_optional_pos;
1199
719
    }
1200
0
    start = args[1];
1201
719
skip_optional_pos:
1202
719
    return_value = builtin_sum_impl(module, iterable, start);
1203
1204
719
exit:
1205
719
    return return_value;
1206
719
}
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
546
{
1228
546
    PyObject *return_value = NULL;
1229
546
    PyObject *obj;
1230
546
    PyObject *class_or_tuple;
1231
1232
546
    if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
1233
0
        goto exit;
1234
0
    }
1235
546
    obj = args[0];
1236
546
    class_or_tuple = args[1];
1237
546
    return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
1238
1239
546
exit:
1240
546
    return return_value;
1241
546
}
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
70
{
1263
70
    PyObject *return_value = NULL;
1264
70
    PyObject *cls;
1265
70
    PyObject *class_or_tuple;
1266
1267
70
    if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
1268
0
        goto exit;
1269
0
    }
1270
70
    cls = args[0];
1271
70
    class_or_tuple = args[1];
1272
70
    return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
1273
1274
70
exit:
1275
70
    return return_value;
1276
70
}
1277
/*[clinic end generated code: output=c0b72519622c849e input=a9049054013a1b77]*/