Coverage Report

Created: 2025-11-11 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Python/clinic/bltinmodule.c.h
Line
Count
Source
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
#  include "pycore_gc.h"          // PyGC_Head
7
#  include "pycore_runtime.h"     // _Py_ID()
8
#endif
9
#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
10
11
PyDoc_STRVAR(builtin___import____doc__,
12
"__import__($module, /, name, globals=None, locals=None, fromlist=(),\n"
13
"           level=0)\n"
14
"--\n"
15
"\n"
16
"Import a module.\n"
17
"\n"
18
"Because this function is meant for use by the Python\n"
19
"interpreter and not for general use, it is better to use\n"
20
"importlib.import_module() to programmatically import a module.\n"
21
"\n"
22
"The globals argument is only used to determine the context;\n"
23
"they are not modified.  The locals argument is unused.  The fromlist\n"
24
"should be a list of names to emulate ``from name import ...``, or an\n"
25
"empty list to emulate ``import name``.\n"
26
"When importing a module from a package, note that __import__(\'A.B\', ...)\n"
27
"returns package A when fromlist is empty, but its submodule B when\n"
28
"fromlist is not empty.  The level argument is used to determine whether to\n"
29
"perform absolute or relative imports: 0 is absolute, while a positive number\n"
30
"is the number of parent directories to search relative to the current module.");
31
32
#define BUILTIN___IMPORT___METHODDEF    \
33
    {"__import__", _PyCFunction_CAST(builtin___import__), METH_FASTCALL|METH_KEYWORDS, builtin___import____doc__},
34
35
static PyObject *
36
builtin___import___impl(PyObject *module, PyObject *name, PyObject *globals,
37
                        PyObject *locals, PyObject *fromlist, int level);
38
39
static PyObject *
40
builtin___import__(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
41
13.4k
{
42
13.4k
    PyObject *return_value = NULL;
43
13.4k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
44
45
13.4k
    #define NUM_KEYWORDS 5
46
13.4k
    static struct {
47
13.4k
        PyGC_Head _this_is_not_used;
48
13.4k
        PyObject_VAR_HEAD
49
13.4k
        Py_hash_t ob_hash;
50
13.4k
        PyObject *ob_item[NUM_KEYWORDS];
51
13.4k
    } _kwtuple = {
52
13.4k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
53
13.4k
        .ob_hash = -1,
54
13.4k
        .ob_item = { &_Py_ID(name), &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(fromlist), &_Py_ID(level), },
55
13.4k
    };
56
13.4k
    #undef NUM_KEYWORDS
57
13.4k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
58
59
    #else  // !Py_BUILD_CORE
60
    #  define KWTUPLE NULL
61
    #endif  // !Py_BUILD_CORE
62
63
13.4k
    static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL};
64
13.4k
    static _PyArg_Parser _parser = {
65
13.4k
        .keywords = _keywords,
66
13.4k
        .fname = "__import__",
67
13.4k
        .kwtuple = KWTUPLE,
68
13.4k
    };
69
13.4k
    #undef KWTUPLE
70
13.4k
    PyObject *argsbuf[5];
71
13.4k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
72
13.4k
    PyObject *name;
73
13.4k
    PyObject *globals = NULL;
74
13.4k
    PyObject *locals = NULL;
75
13.4k
    PyObject *fromlist = NULL;
76
13.4k
    int level = 0;
77
78
13.4k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
79
13.4k
            /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
80
13.4k
    if (!args) {
81
0
        goto exit;
82
0
    }
83
13.4k
    name = args[0];
84
13.4k
    if (!noptargs) {
85
231
        goto skip_optional_pos;
86
231
    }
87
13.2k
    if (args[1]) {
88
5.55k
        globals = args[1];
89
5.55k
        if (!--noptargs) {
90
0
            goto skip_optional_pos;
91
0
        }
92
5.55k
    }
93
13.2k
    if (args[2]) {
94
5.55k
        locals = args[2];
95
5.55k
        if (!--noptargs) {
96
0
            goto skip_optional_pos;
97
0
        }
98
5.55k
    }
99
13.2k
    if (args[3]) {
100
13.2k
        fromlist = args[3];
101
13.2k
        if (!--noptargs) {
102
0
            goto skip_optional_pos;
103
0
        }
104
13.2k
    }
105
13.2k
    level = PyLong_AsInt(args[4]);
106
13.2k
    if (level == -1 && PyErr_Occurred()) {
107
0
        goto exit;
108
0
    }
109
13.4k
skip_optional_pos:
110
13.4k
    return_value = builtin___import___impl(module, name, globals, locals, fromlist, level);
111
112
13.4k
exit:
113
13.4k
    return return_value;
114
13.4k
}
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.4k
{
268
21.4k
    PyObject *return_value = NULL;
269
21.4k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
270
271
21.4k
    #define NUM_KEYWORDS 7
272
21.4k
    static struct {
273
21.4k
        PyGC_Head _this_is_not_used;
274
21.4k
        PyObject_VAR_HEAD
275
21.4k
        Py_hash_t ob_hash;
276
21.4k
        PyObject *ob_item[NUM_KEYWORDS];
277
21.4k
    } _kwtuple = {
278
21.4k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
279
21.4k
        .ob_hash = -1,
280
21.4k
        .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.4k
    };
282
21.4k
    #undef NUM_KEYWORDS
283
21.4k
    #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.4k
    static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "_feature_version", NULL};
290
21.4k
    static _PyArg_Parser _parser = {
291
21.4k
        .keywords = _keywords,
292
21.4k
        .fname = "compile",
293
21.4k
        .kwtuple = KWTUPLE,
294
21.4k
    };
295
21.4k
    #undef KWTUPLE
296
21.4k
    PyObject *argsbuf[7];
297
21.4k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
298
21.4k
    PyObject *source;
299
21.4k
    PyObject *filename = NULL;
300
21.4k
    const char *mode;
301
21.4k
    int flags = 0;
302
21.4k
    int dont_inherit = 0;
303
21.4k
    int optimize = -1;
304
21.4k
    int feature_version = -1;
305
306
21.4k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
307
21.4k
            /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
308
21.4k
    if (!args) {
309
0
        goto exit;
310
0
    }
311
21.4k
    source = args[0];
312
21.4k
    if (!PyUnicode_FSDecoder(args[1], &filename)) {
313
0
        goto exit;
314
0
    }
315
21.4k
    if (!PyUnicode_Check(args[2])) {
316
0
        _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]);
317
0
        goto exit;
318
0
    }
319
21.4k
    Py_ssize_t mode_length;
320
21.4k
    mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length);
321
21.4k
    if (mode == NULL) {
322
0
        goto exit;
323
0
    }
324
21.4k
    if (strlen(mode) != (size_t)mode_length) {
325
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
326
0
        goto exit;
327
0
    }
328
21.4k
    if (!noptargs) {
329
0
        goto skip_optional_pos;
330
0
    }
331
21.4k
    if (args[3]) {
332
21.1k
        flags = PyLong_AsInt(args[3]);
333
21.1k
        if (flags == -1 && PyErr_Occurred()) {
334
0
            goto exit;
335
0
        }
336
21.1k
        if (!--noptargs) {
337
0
            goto skip_optional_pos;
338
0
        }
339
21.1k
    }
340
21.4k
    if (args[4]) {
341
260
        dont_inherit = PyObject_IsTrue(args[4]);
342
260
        if (dont_inherit < 0) {
343
0
            goto exit;
344
0
        }
345
260
        if (!--noptargs) {
346
0
            goto skip_optional_pos;
347
0
        }
348
260
    }
349
21.4k
    if (args[5]) {
350
21.4k
        optimize = PyLong_AsInt(args[5]);
351
21.4k
        if (optimize == -1 && PyErr_Occurred()) {
352
0
            goto exit;
353
0
        }
354
21.4k
        if (!--noptargs) {
355
260
            goto skip_optional_pos;
356
260
        }
357
21.4k
    }
358
21.4k
skip_optional_pos:
359
21.4k
    if (!noptargs) {
360
260
        goto skip_optional_kwonly;
361
260
    }
362
21.1k
    feature_version = PyLong_AsInt(args[6]);
363
21.1k
    if (feature_version == -1 && PyErr_Occurred()) {
364
0
        goto exit;
365
0
    }
366
21.4k
skip_optional_kwonly:
367
21.4k
    return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version);
368
369
21.4k
exit:
370
    /* Cleanup for filename */
371
21.4k
    Py_XDECREF(filename);
372
373
21.4k
    return return_value;
374
21.4k
}
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
0
{
391
0
    PyObject *return_value = NULL;
392
0
    PyObject *x;
393
0
    PyObject *y;
394
395
0
    if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
396
0
        goto exit;
397
0
    }
398
0
    x = args[0];
399
0
    y = args[1];
400
0
    return_value = builtin_divmod_impl(module, x, y);
401
402
0
exit:
403
0
    return return_value;
404
0
}
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
75
{
428
75
    PyObject *return_value = NULL;
429
75
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
430
431
75
    #define NUM_KEYWORDS 2
432
75
    static struct {
433
75
        PyGC_Head _this_is_not_used;
434
75
        PyObject_VAR_HEAD
435
75
        Py_hash_t ob_hash;
436
75
        PyObject *ob_item[NUM_KEYWORDS];
437
75
    } _kwtuple = {
438
75
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
439
75
        .ob_hash = -1,
440
75
        .ob_item = { &_Py_ID(globals), &_Py_ID(locals), },
441
75
    };
442
75
    #undef NUM_KEYWORDS
443
75
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
444
445
    #else  // !Py_BUILD_CORE
446
    #  define KWTUPLE NULL
447
    #endif  // !Py_BUILD_CORE
448
449
75
    static const char * const _keywords[] = {"", "globals", "locals", NULL};
450
75
    static _PyArg_Parser _parser = {
451
75
        .keywords = _keywords,
452
75
        .fname = "eval",
453
75
        .kwtuple = KWTUPLE,
454
75
    };
455
75
    #undef KWTUPLE
456
75
    PyObject *argsbuf[3];
457
75
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
458
75
    PyObject *source;
459
75
    PyObject *globals = Py_None;
460
75
    PyObject *locals = Py_None;
461
462
75
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
463
75
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
464
75
    if (!args) {
465
0
        goto exit;
466
0
    }
467
75
    source = args[0];
468
75
    if (!noptargs) {
469
0
        goto skip_optional_pos;
470
0
    }
471
75
    if (args[1]) {
472
75
        globals = args[1];
473
75
        if (!--noptargs) {
474
75
            goto skip_optional_pos;
475
75
        }
476
75
    }
477
0
    locals = args[2];
478
75
skip_optional_pos:
479
75
    return_value = builtin_eval_impl(module, source, globals, locals);
480
481
75
exit:
482
75
    return return_value;
483
75
}
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
1.21k
{
509
1.21k
    PyObject *return_value = NULL;
510
1.21k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
511
512
1.21k
    #define NUM_KEYWORDS 3
513
1.21k
    static struct {
514
1.21k
        PyGC_Head _this_is_not_used;
515
1.21k
        PyObject_VAR_HEAD
516
1.21k
        Py_hash_t ob_hash;
517
1.21k
        PyObject *ob_item[NUM_KEYWORDS];
518
1.21k
    } _kwtuple = {
519
1.21k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
520
1.21k
        .ob_hash = -1,
521
1.21k
        .ob_item = { &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(closure), },
522
1.21k
    };
523
1.21k
    #undef NUM_KEYWORDS
524
1.21k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
525
526
    #else  // !Py_BUILD_CORE
527
    #  define KWTUPLE NULL
528
    #endif  // !Py_BUILD_CORE
529
530
1.21k
    static const char * const _keywords[] = {"", "globals", "locals", "closure", NULL};
531
1.21k
    static _PyArg_Parser _parser = {
532
1.21k
        .keywords = _keywords,
533
1.21k
        .fname = "exec",
534
1.21k
        .kwtuple = KWTUPLE,
535
1.21k
    };
536
1.21k
    #undef KWTUPLE
537
1.21k
    PyObject *argsbuf[4];
538
1.21k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
539
1.21k
    PyObject *source;
540
1.21k
    PyObject *globals = Py_None;
541
1.21k
    PyObject *locals = Py_None;
542
1.21k
    PyObject *closure = NULL;
543
544
1.21k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
545
1.21k
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
546
1.21k
    if (!args) {
547
0
        goto exit;
548
0
    }
549
1.21k
    source = args[0];
550
1.21k
    if (!noptargs) {
551
0
        goto skip_optional_pos;
552
0
    }
553
1.21k
    if (args[1]) {
554
1.21k
        globals = args[1];
555
1.21k
        if (!--noptargs) {
556
1.20k
            goto skip_optional_pos;
557
1.20k
        }
558
1.21k
    }
559
12
    if (args[2]) {
560
12
        locals = args[2];
561
12
        if (!--noptargs) {
562
12
            goto skip_optional_pos;
563
12
        }
564
12
    }
565
1.21k
skip_optional_pos:
566
1.21k
    if (!noptargs) {
567
1.21k
        goto skip_optional_kwonly;
568
1.21k
    }
569
0
    closure = args[3];
570
1.21k
skip_optional_kwonly:
571
1.21k
    return_value = builtin_exec_impl(module, source, globals, locals, closure);
572
573
1.21k
exit:
574
1.21k
    return return_value;
575
1.21k
}
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
507
{
595
507
    return builtin_globals_impl(module);
596
507
}
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
8.00M
{
615
8.00M
    PyObject *return_value = NULL;
616
8.00M
    PyObject *obj;
617
8.00M
    PyObject *name;
618
619
8.00M
    if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
620
0
        goto exit;
621
0
    }
622
8.00M
    obj = args[0];
623
8.00M
    name = args[1];
624
8.00M
    return_value = builtin_hasattr_impl(module, obj, name);
625
626
8.00M
exit:
627
8.00M
    return return_value;
628
8.00M
}
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
300
{
648
300
    PyObject *return_value = NULL;
649
650
300
    return_value = builtin_id_impl((PyModuleDef *)self, v);
651
652
300
    return return_value;
653
300
}
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
4.37k
{
673
4.37k
    PyObject *return_value = NULL;
674
4.37k
    PyObject *obj;
675
4.37k
    PyObject *name;
676
4.37k
    PyObject *value;
677
678
4.37k
    if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) {
679
0
        goto exit;
680
0
    }
681
4.37k
    obj = args[0];
682
4.37k
    name = args[1];
683
4.37k
    value = args[2];
684
4.37k
    return_value = builtin_setattr_impl(module, obj, name, value);
685
686
4.37k
exit:
687
4.37k
    return return_value;
688
4.37k
}
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
780
{
707
780
    PyObject *return_value = NULL;
708
780
    PyObject *obj;
709
780
    PyObject *name;
710
711
780
    if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
712
0
        goto exit;
713
0
    }
714
780
    obj = args[0];
715
780
    name = args[1];
716
780
    return_value = builtin_delattr_impl(module, obj, name);
717
718
780
exit:
719
780
    return return_value;
720
780
}
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
0
{
870
0
    PyObject *return_value = NULL;
871
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
872
873
0
    #define NUM_KEYWORDS 3
874
0
    static struct {
875
0
        PyGC_Head _this_is_not_used;
876
0
        PyObject_VAR_HEAD
877
0
        Py_hash_t ob_hash;
878
0
        PyObject *ob_item[NUM_KEYWORDS];
879
0
    } _kwtuple = {
880
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
881
0
        .ob_hash = -1,
882
0
        .ob_item = { &_Py_ID(base), &_Py_ID(exp), &_Py_ID(mod), },
883
0
    };
884
0
    #undef NUM_KEYWORDS
885
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
886
887
    #else  // !Py_BUILD_CORE
888
    #  define KWTUPLE NULL
889
    #endif  // !Py_BUILD_CORE
890
891
0
    static const char * const _keywords[] = {"base", "exp", "mod", NULL};
892
0
    static _PyArg_Parser _parser = {
893
0
        .keywords = _keywords,
894
0
        .fname = "pow",
895
0
        .kwtuple = KWTUPLE,
896
0
    };
897
0
    #undef KWTUPLE
898
0
    PyObject *argsbuf[3];
899
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
900
0
    PyObject *base;
901
0
    PyObject *exp;
902
0
    PyObject *mod = Py_None;
903
904
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
905
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
906
0
    if (!args) {
907
0
        goto exit;
908
0
    }
909
0
    base = args[0];
910
0
    exp = args[1];
911
0
    if (!noptargs) {
912
0
        goto skip_optional_pos;
913
0
    }
914
0
    mod = args[2];
915
0
skip_optional_pos:
916
0
    return_value = builtin_pow_impl(module, base, exp, mod);
917
918
0
exit:
919
0
    return return_value;
920
0
}
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
10.7M
{
1161
10.7M
    PyObject *return_value = NULL;
1162
10.7M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1163
1164
10.7M
    #define NUM_KEYWORDS 1
1165
10.7M
    static struct {
1166
10.7M
        PyGC_Head _this_is_not_used;
1167
10.7M
        PyObject_VAR_HEAD
1168
10.7M
        Py_hash_t ob_hash;
1169
10.7M
        PyObject *ob_item[NUM_KEYWORDS];
1170
10.7M
    } _kwtuple = {
1171
10.7M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1172
10.7M
        .ob_hash = -1,
1173
10.7M
        .ob_item = { &_Py_ID(start), },
1174
10.7M
    };
1175
10.7M
    #undef NUM_KEYWORDS
1176
10.7M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1177
1178
    #else  // !Py_BUILD_CORE
1179
    #  define KWTUPLE NULL
1180
    #endif  // !Py_BUILD_CORE
1181
1182
10.7M
    static const char * const _keywords[] = {"", "start", NULL};
1183
10.7M
    static _PyArg_Parser _parser = {
1184
10.7M
        .keywords = _keywords,
1185
10.7M
        .fname = "sum",
1186
10.7M
        .kwtuple = KWTUPLE,
1187
10.7M
    };
1188
10.7M
    #undef KWTUPLE
1189
10.7M
    PyObject *argsbuf[2];
1190
10.7M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1191
10.7M
    PyObject *iterable;
1192
10.7M
    PyObject *start = NULL;
1193
1194
10.7M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1195
10.7M
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1196
10.7M
    if (!args) {
1197
0
        goto exit;
1198
0
    }
1199
10.7M
    iterable = args[0];
1200
10.7M
    if (!noptargs) {
1201
944k
        goto skip_optional_pos;
1202
944k
    }
1203
9.77M
    start = args[1];
1204
10.7M
skip_optional_pos:
1205
10.7M
    return_value = builtin_sum_impl(module, iterable, start);
1206
1207
10.7M
exit:
1208
10.7M
    return return_value;
1209
10.7M
}
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
1.02k
{
1231
1.02k
    PyObject *return_value = NULL;
1232
1.02k
    PyObject *obj;
1233
1.02k
    PyObject *class_or_tuple;
1234
1235
1.02k
    if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
1236
0
        goto exit;
1237
0
    }
1238
1.02k
    obj = args[0];
1239
1.02k
    class_or_tuple = args[1];
1240
1.02k
    return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
1241
1242
1.02k
exit:
1243
1.02k
    return return_value;
1244
1.02k
}
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
2.23k
{
1266
2.23k
    PyObject *return_value = NULL;
1267
2.23k
    PyObject *cls;
1268
2.23k
    PyObject *class_or_tuple;
1269
1270
2.23k
    if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
1271
0
        goto exit;
1272
0
    }
1273
2.23k
    cls = args[0];
1274
2.23k
    class_or_tuple = args[1];
1275
2.23k
    return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
1276
1277
2.23k
exit:
1278
2.23k
    return return_value;
1279
2.23k
}
1280
/*[clinic end generated code: output=7eada753dc2e046f input=a9049054013a1b77]*/