Coverage Report

Created: 2026-10-31 06:21

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