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