Coverage Report

Created: 2026-06-07 06:26

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