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