Coverage Report

Created: 2025-11-30 06:38

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