/src/Python-3.8.3/Python/clinic/bltinmodule.c.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | PyDoc_STRVAR(builtin_abs__doc__, |
6 | | "abs($module, x, /)\n" |
7 | | "--\n" |
8 | | "\n" |
9 | | "Return the absolute value of the argument."); |
10 | | |
11 | | #define BUILTIN_ABS_METHODDEF \ |
12 | | {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__}, |
13 | | |
14 | | PyDoc_STRVAR(builtin_all__doc__, |
15 | | "all($module, iterable, /)\n" |
16 | | "--\n" |
17 | | "\n" |
18 | | "Return True if bool(x) is True for all values x in the iterable.\n" |
19 | | "\n" |
20 | | "If the iterable is empty, return True."); |
21 | | |
22 | | #define BUILTIN_ALL_METHODDEF \ |
23 | | {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__}, |
24 | | |
25 | | PyDoc_STRVAR(builtin_any__doc__, |
26 | | "any($module, iterable, /)\n" |
27 | | "--\n" |
28 | | "\n" |
29 | | "Return True if bool(x) is True for any x in the iterable.\n" |
30 | | "\n" |
31 | | "If the iterable is empty, return False."); |
32 | | |
33 | | #define BUILTIN_ANY_METHODDEF \ |
34 | | {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__}, |
35 | | |
36 | | PyDoc_STRVAR(builtin_ascii__doc__, |
37 | | "ascii($module, obj, /)\n" |
38 | | "--\n" |
39 | | "\n" |
40 | | "Return an ASCII-only representation of an object.\n" |
41 | | "\n" |
42 | | "As repr(), return a string containing a printable representation of an\n" |
43 | | "object, but escape the non-ASCII characters in the string returned by\n" |
44 | | "repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n" |
45 | | "to that returned by repr() in Python 2."); |
46 | | |
47 | | #define BUILTIN_ASCII_METHODDEF \ |
48 | | {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__}, |
49 | | |
50 | | PyDoc_STRVAR(builtin_bin__doc__, |
51 | | "bin($module, number, /)\n" |
52 | | "--\n" |
53 | | "\n" |
54 | | "Return the binary representation of an integer.\n" |
55 | | "\n" |
56 | | " >>> bin(2796202)\n" |
57 | | " \'0b1010101010101010101010\'"); |
58 | | |
59 | | #define BUILTIN_BIN_METHODDEF \ |
60 | | {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__}, |
61 | | |
62 | | PyDoc_STRVAR(builtin_callable__doc__, |
63 | | "callable($module, obj, /)\n" |
64 | | "--\n" |
65 | | "\n" |
66 | | "Return whether the object is callable (i.e., some kind of function).\n" |
67 | | "\n" |
68 | | "Note that classes are callable, as are instances of classes with a\n" |
69 | | "__call__() method."); |
70 | | |
71 | | #define BUILTIN_CALLABLE_METHODDEF \ |
72 | | {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__}, |
73 | | |
74 | | PyDoc_STRVAR(builtin_format__doc__, |
75 | | "format($module, value, format_spec=\'\', /)\n" |
76 | | "--\n" |
77 | | "\n" |
78 | | "Return value.__format__(format_spec)\n" |
79 | | "\n" |
80 | | "format_spec defaults to the empty string.\n" |
81 | | "See the Format Specification Mini-Language section of help(\'FORMATTING\') for\n" |
82 | | "details."); |
83 | | |
84 | | #define BUILTIN_FORMAT_METHODDEF \ |
85 | | {"format", (PyCFunction)(void(*)(void))builtin_format, METH_FASTCALL, builtin_format__doc__}, |
86 | | |
87 | | static PyObject * |
88 | | builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec); |
89 | | |
90 | | static PyObject * |
91 | | builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
92 | 0 | { |
93 | 0 | PyObject *return_value = NULL; |
94 | 0 | PyObject *value; |
95 | 0 | PyObject *format_spec = NULL; |
96 | |
|
97 | 0 | if (!_PyArg_CheckPositional("format", nargs, 1, 2)) { |
98 | 0 | goto exit; |
99 | 0 | } |
100 | 0 | value = args[0]; |
101 | 0 | if (nargs < 2) { |
102 | 0 | goto skip_optional; |
103 | 0 | } |
104 | 0 | if (!PyUnicode_Check(args[1])) { |
105 | 0 | _PyArg_BadArgument("format", "argument 2", "str", args[1]); |
106 | 0 | goto exit; |
107 | 0 | } |
108 | 0 | if (PyUnicode_READY(args[1]) == -1) { |
109 | 0 | goto exit; |
110 | 0 | } |
111 | 0 | format_spec = args[1]; |
112 | 0 | skip_optional: |
113 | 0 | return_value = builtin_format_impl(module, value, format_spec); |
114 | |
|
115 | 0 | exit: |
116 | 0 | return return_value; |
117 | 0 | } |
118 | | |
119 | | PyDoc_STRVAR(builtin_chr__doc__, |
120 | | "chr($module, i, /)\n" |
121 | | "--\n" |
122 | | "\n" |
123 | | "Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); |
124 | | |
125 | | #define BUILTIN_CHR_METHODDEF \ |
126 | | {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__}, |
127 | | |
128 | | static PyObject * |
129 | | builtin_chr_impl(PyObject *module, int i); |
130 | | |
131 | | static PyObject * |
132 | | builtin_chr(PyObject *module, PyObject *arg) |
133 | 24 | { |
134 | 24 | PyObject *return_value = NULL; |
135 | 24 | int i; |
136 | | |
137 | 24 | if (PyFloat_Check(arg)) { |
138 | 0 | PyErr_SetString(PyExc_TypeError, |
139 | 0 | "integer argument expected, got float" ); |
140 | 0 | goto exit; |
141 | 0 | } |
142 | 24 | i = _PyLong_AsInt(arg); |
143 | 24 | if (i == -1 && PyErr_Occurred()) { |
144 | 0 | goto exit; |
145 | 0 | } |
146 | 24 | return_value = builtin_chr_impl(module, i); |
147 | | |
148 | 24 | exit: |
149 | 24 | return return_value; |
150 | 24 | } |
151 | | |
152 | | PyDoc_STRVAR(builtin_compile__doc__, |
153 | | "compile($module, /, source, filename, mode, flags=0,\n" |
154 | | " dont_inherit=False, optimize=-1, *, _feature_version=-1)\n" |
155 | | "--\n" |
156 | | "\n" |
157 | | "Compile source into a code object that can be executed by exec() or eval().\n" |
158 | | "\n" |
159 | | "The source code may represent a Python module, statement or expression.\n" |
160 | | "The filename will be used for run-time error messages.\n" |
161 | | "The mode must be \'exec\' to compile a module, \'single\' to compile a\n" |
162 | | "single (interactive) statement, or \'eval\' to compile an expression.\n" |
163 | | "The flags argument, if present, controls which future statements influence\n" |
164 | | "the compilation of the code.\n" |
165 | | "The dont_inherit argument, if true, stops the compilation inheriting\n" |
166 | | "the effects of any future statements in effect in the code calling\n" |
167 | | "compile; if absent or false these statements do influence the compilation,\n" |
168 | | "in addition to any features explicitly specified."); |
169 | | |
170 | | #define BUILTIN_COMPILE_METHODDEF \ |
171 | | {"compile", (PyCFunction)(void(*)(void))builtin_compile, METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__}, |
172 | | |
173 | | static PyObject * |
174 | | builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, |
175 | | const char *mode, int flags, int dont_inherit, |
176 | | int optimize, int feature_version); |
177 | | |
178 | | static PyObject * |
179 | | builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
180 | 0 | { |
181 | 0 | PyObject *return_value = NULL; |
182 | 0 | static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "_feature_version", NULL}; |
183 | 0 | static _PyArg_Parser _parser = {NULL, _keywords, "compile", 0}; |
184 | 0 | PyObject *argsbuf[7]; |
185 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
186 | 0 | PyObject *source; |
187 | 0 | PyObject *filename; |
188 | 0 | const char *mode; |
189 | 0 | int flags = 0; |
190 | 0 | int dont_inherit = 0; |
191 | 0 | int optimize = -1; |
192 | 0 | int feature_version = -1; |
193 | |
|
194 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf); |
195 | 0 | if (!args) { |
196 | 0 | goto exit; |
197 | 0 | } |
198 | 0 | source = args[0]; |
199 | 0 | if (!PyUnicode_FSDecoder(args[1], &filename)) { |
200 | 0 | goto exit; |
201 | 0 | } |
202 | 0 | if (!PyUnicode_Check(args[2])) { |
203 | 0 | _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]); |
204 | 0 | goto exit; |
205 | 0 | } |
206 | 0 | Py_ssize_t mode_length; |
207 | 0 | mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length); |
208 | 0 | if (mode == NULL) { |
209 | 0 | goto exit; |
210 | 0 | } |
211 | 0 | if (strlen(mode) != (size_t)mode_length) { |
212 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
213 | 0 | goto exit; |
214 | 0 | } |
215 | 0 | if (!noptargs) { |
216 | 0 | goto skip_optional_pos; |
217 | 0 | } |
218 | 0 | if (args[3]) { |
219 | 0 | if (PyFloat_Check(args[3])) { |
220 | 0 | PyErr_SetString(PyExc_TypeError, |
221 | 0 | "integer argument expected, got float" ); |
222 | 0 | goto exit; |
223 | 0 | } |
224 | 0 | flags = _PyLong_AsInt(args[3]); |
225 | 0 | if (flags == -1 && PyErr_Occurred()) { |
226 | 0 | goto exit; |
227 | 0 | } |
228 | 0 | if (!--noptargs) { |
229 | 0 | goto skip_optional_pos; |
230 | 0 | } |
231 | 0 | } |
232 | 0 | if (args[4]) { |
233 | 0 | if (PyFloat_Check(args[4])) { |
234 | 0 | PyErr_SetString(PyExc_TypeError, |
235 | 0 | "integer argument expected, got float" ); |
236 | 0 | goto exit; |
237 | 0 | } |
238 | 0 | dont_inherit = _PyLong_AsInt(args[4]); |
239 | 0 | if (dont_inherit == -1 && PyErr_Occurred()) { |
240 | 0 | goto exit; |
241 | 0 | } |
242 | 0 | if (!--noptargs) { |
243 | 0 | goto skip_optional_pos; |
244 | 0 | } |
245 | 0 | } |
246 | 0 | if (args[5]) { |
247 | 0 | if (PyFloat_Check(args[5])) { |
248 | 0 | PyErr_SetString(PyExc_TypeError, |
249 | 0 | "integer argument expected, got float" ); |
250 | 0 | goto exit; |
251 | 0 | } |
252 | 0 | optimize = _PyLong_AsInt(args[5]); |
253 | 0 | if (optimize == -1 && PyErr_Occurred()) { |
254 | 0 | goto exit; |
255 | 0 | } |
256 | 0 | if (!--noptargs) { |
257 | 0 | goto skip_optional_pos; |
258 | 0 | } |
259 | 0 | } |
260 | 0 | skip_optional_pos: |
261 | 0 | if (!noptargs) { |
262 | 0 | goto skip_optional_kwonly; |
263 | 0 | } |
264 | 0 | if (PyFloat_Check(args[6])) { |
265 | 0 | PyErr_SetString(PyExc_TypeError, |
266 | 0 | "integer argument expected, got float" ); |
267 | 0 | goto exit; |
268 | 0 | } |
269 | 0 | feature_version = _PyLong_AsInt(args[6]); |
270 | 0 | if (feature_version == -1 && PyErr_Occurred()) { |
271 | 0 | goto exit; |
272 | 0 | } |
273 | 0 | skip_optional_kwonly: |
274 | 0 | return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version); |
275 | |
|
276 | 0 | exit: |
277 | 0 | return return_value; |
278 | 0 | } |
279 | | |
280 | | PyDoc_STRVAR(builtin_divmod__doc__, |
281 | | "divmod($module, x, y, /)\n" |
282 | | "--\n" |
283 | | "\n" |
284 | | "Return the tuple (x//y, x%y). Invariant: div*y + mod == x."); |
285 | | |
286 | | #define BUILTIN_DIVMOD_METHODDEF \ |
287 | | {"divmod", (PyCFunction)(void(*)(void))builtin_divmod, METH_FASTCALL, builtin_divmod__doc__}, |
288 | | |
289 | | static PyObject * |
290 | | builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y); |
291 | | |
292 | | static PyObject * |
293 | | builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
294 | 0 | { |
295 | 0 | PyObject *return_value = NULL; |
296 | 0 | PyObject *x; |
297 | 0 | PyObject *y; |
298 | |
|
299 | 0 | if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) { |
300 | 0 | goto exit; |
301 | 0 | } |
302 | 0 | x = args[0]; |
303 | 0 | y = args[1]; |
304 | 0 | return_value = builtin_divmod_impl(module, x, y); |
305 | |
|
306 | 0 | exit: |
307 | 0 | return return_value; |
308 | 0 | } |
309 | | |
310 | | PyDoc_STRVAR(builtin_eval__doc__, |
311 | | "eval($module, source, globals=None, locals=None, /)\n" |
312 | | "--\n" |
313 | | "\n" |
314 | | "Evaluate the given source in the context of globals and locals.\n" |
315 | | "\n" |
316 | | "The source may be a string representing a Python expression\n" |
317 | | "or a code object as returned by compile().\n" |
318 | | "The globals must be a dictionary and locals can be any mapping,\n" |
319 | | "defaulting to the current globals and locals.\n" |
320 | | "If only globals is given, locals defaults to it."); |
321 | | |
322 | | #define BUILTIN_EVAL_METHODDEF \ |
323 | | {"eval", (PyCFunction)(void(*)(void))builtin_eval, METH_FASTCALL, builtin_eval__doc__}, |
324 | | |
325 | | static PyObject * |
326 | | builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, |
327 | | PyObject *locals); |
328 | | |
329 | | static PyObject * |
330 | | builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
331 | 0 | { |
332 | 0 | PyObject *return_value = NULL; |
333 | 0 | PyObject *source; |
334 | 0 | PyObject *globals = Py_None; |
335 | 0 | PyObject *locals = Py_None; |
336 | |
|
337 | 0 | if (!_PyArg_CheckPositional("eval", nargs, 1, 3)) { |
338 | 0 | goto exit; |
339 | 0 | } |
340 | 0 | source = args[0]; |
341 | 0 | if (nargs < 2) { |
342 | 0 | goto skip_optional; |
343 | 0 | } |
344 | 0 | globals = args[1]; |
345 | 0 | if (nargs < 3) { |
346 | 0 | goto skip_optional; |
347 | 0 | } |
348 | 0 | locals = args[2]; |
349 | 0 | skip_optional: |
350 | 0 | return_value = builtin_eval_impl(module, source, globals, locals); |
351 | |
|
352 | 0 | exit: |
353 | 0 | return return_value; |
354 | 0 | } |
355 | | |
356 | | PyDoc_STRVAR(builtin_exec__doc__, |
357 | | "exec($module, source, globals=None, locals=None, /)\n" |
358 | | "--\n" |
359 | | "\n" |
360 | | "Execute the given source in the context of globals and locals.\n" |
361 | | "\n" |
362 | | "The source may be a string representing one or more Python statements\n" |
363 | | "or a code object as returned by compile().\n" |
364 | | "The globals must be a dictionary and locals can be any mapping,\n" |
365 | | "defaulting to the current globals and locals.\n" |
366 | | "If only globals is given, locals defaults to it."); |
367 | | |
368 | | #define BUILTIN_EXEC_METHODDEF \ |
369 | | {"exec", (PyCFunction)(void(*)(void))builtin_exec, METH_FASTCALL, builtin_exec__doc__}, |
370 | | |
371 | | static PyObject * |
372 | | builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, |
373 | | PyObject *locals); |
374 | | |
375 | | static PyObject * |
376 | | builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
377 | 265 | { |
378 | 265 | PyObject *return_value = NULL; |
379 | 265 | PyObject *source; |
380 | 265 | PyObject *globals = Py_None; |
381 | 265 | PyObject *locals = Py_None; |
382 | | |
383 | 265 | if (!_PyArg_CheckPositional("exec", nargs, 1, 3)) { |
384 | 0 | goto exit; |
385 | 0 | } |
386 | 265 | source = args[0]; |
387 | 265 | if (nargs < 2) { |
388 | 0 | goto skip_optional; |
389 | 0 | } |
390 | 265 | globals = args[1]; |
391 | 265 | if (nargs < 3) { |
392 | 265 | goto skip_optional; |
393 | 265 | } |
394 | 0 | locals = args[2]; |
395 | 265 | skip_optional: |
396 | 265 | return_value = builtin_exec_impl(module, source, globals, locals); |
397 | | |
398 | 265 | exit: |
399 | 265 | return return_value; |
400 | 265 | } |
401 | | |
402 | | PyDoc_STRVAR(builtin_globals__doc__, |
403 | | "globals($module, /)\n" |
404 | | "--\n" |
405 | | "\n" |
406 | | "Return the dictionary containing the current scope\'s global variables.\n" |
407 | | "\n" |
408 | | "NOTE: Updates to this dictionary *will* affect name lookups in the current\n" |
409 | | "global scope and vice-versa."); |
410 | | |
411 | | #define BUILTIN_GLOBALS_METHODDEF \ |
412 | | {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__}, |
413 | | |
414 | | static PyObject * |
415 | | builtin_globals_impl(PyObject *module); |
416 | | |
417 | | static PyObject * |
418 | | builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
419 | 160 | { |
420 | 160 | return builtin_globals_impl(module); |
421 | 160 | } |
422 | | |
423 | | PyDoc_STRVAR(builtin_hasattr__doc__, |
424 | | "hasattr($module, obj, name, /)\n" |
425 | | "--\n" |
426 | | "\n" |
427 | | "Return whether the object has an attribute with the given name.\n" |
428 | | "\n" |
429 | | "This is done by calling getattr(obj, name) and catching AttributeError."); |
430 | | |
431 | | #define BUILTIN_HASATTR_METHODDEF \ |
432 | | {"hasattr", (PyCFunction)(void(*)(void))builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__}, |
433 | | |
434 | | static PyObject * |
435 | | builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
436 | | |
437 | | static PyObject * |
438 | | builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
439 | 2.29k | { |
440 | 2.29k | PyObject *return_value = NULL; |
441 | 2.29k | PyObject *obj; |
442 | 2.29k | PyObject *name; |
443 | | |
444 | 2.29k | if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) { |
445 | 0 | goto exit; |
446 | 0 | } |
447 | 2.29k | obj = args[0]; |
448 | 2.29k | name = args[1]; |
449 | 2.29k | return_value = builtin_hasattr_impl(module, obj, name); |
450 | | |
451 | 2.29k | exit: |
452 | 2.29k | return return_value; |
453 | 2.29k | } |
454 | | |
455 | | PyDoc_STRVAR(builtin_id__doc__, |
456 | | "id($module, obj, /)\n" |
457 | | "--\n" |
458 | | "\n" |
459 | | "Return the identity of an object.\n" |
460 | | "\n" |
461 | | "This is guaranteed to be unique among simultaneously existing objects.\n" |
462 | | "(CPython uses the object\'s memory address.)"); |
463 | | |
464 | | #define BUILTIN_ID_METHODDEF \ |
465 | | {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__}, |
466 | | |
467 | | PyDoc_STRVAR(builtin_setattr__doc__, |
468 | | "setattr($module, obj, name, value, /)\n" |
469 | | "--\n" |
470 | | "\n" |
471 | | "Sets the named attribute on the given object to the specified value.\n" |
472 | | "\n" |
473 | | "setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'"); |
474 | | |
475 | | #define BUILTIN_SETATTR_METHODDEF \ |
476 | | {"setattr", (PyCFunction)(void(*)(void))builtin_setattr, METH_FASTCALL, builtin_setattr__doc__}, |
477 | | |
478 | | static PyObject * |
479 | | builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name, |
480 | | PyObject *value); |
481 | | |
482 | | static PyObject * |
483 | | builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
484 | 846 | { |
485 | 846 | PyObject *return_value = NULL; |
486 | 846 | PyObject *obj; |
487 | 846 | PyObject *name; |
488 | 846 | PyObject *value; |
489 | | |
490 | 846 | if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) { |
491 | 0 | goto exit; |
492 | 0 | } |
493 | 846 | obj = args[0]; |
494 | 846 | name = args[1]; |
495 | 846 | value = args[2]; |
496 | 846 | return_value = builtin_setattr_impl(module, obj, name, value); |
497 | | |
498 | 846 | exit: |
499 | 846 | return return_value; |
500 | 846 | } |
501 | | |
502 | | PyDoc_STRVAR(builtin_delattr__doc__, |
503 | | "delattr($module, obj, name, /)\n" |
504 | | "--\n" |
505 | | "\n" |
506 | | "Deletes the named attribute from the given object.\n" |
507 | | "\n" |
508 | | "delattr(x, \'y\') is equivalent to ``del x.y\'\'"); |
509 | | |
510 | | #define BUILTIN_DELATTR_METHODDEF \ |
511 | | {"delattr", (PyCFunction)(void(*)(void))builtin_delattr, METH_FASTCALL, builtin_delattr__doc__}, |
512 | | |
513 | | static PyObject * |
514 | | builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
515 | | |
516 | | static PyObject * |
517 | | builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
518 | 0 | { |
519 | 0 | PyObject *return_value = NULL; |
520 | 0 | PyObject *obj; |
521 | 0 | PyObject *name; |
522 | |
|
523 | 0 | if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) { |
524 | 0 | goto exit; |
525 | 0 | } |
526 | 0 | obj = args[0]; |
527 | 0 | name = args[1]; |
528 | 0 | return_value = builtin_delattr_impl(module, obj, name); |
529 | |
|
530 | 0 | exit: |
531 | 0 | return return_value; |
532 | 0 | } |
533 | | |
534 | | PyDoc_STRVAR(builtin_hash__doc__, |
535 | | "hash($module, obj, /)\n" |
536 | | "--\n" |
537 | | "\n" |
538 | | "Return the hash value for the given object.\n" |
539 | | "\n" |
540 | | "Two objects that compare equal must also have the same hash value, but the\n" |
541 | | "reverse is not necessarily true."); |
542 | | |
543 | | #define BUILTIN_HASH_METHODDEF \ |
544 | | {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__}, |
545 | | |
546 | | PyDoc_STRVAR(builtin_hex__doc__, |
547 | | "hex($module, number, /)\n" |
548 | | "--\n" |
549 | | "\n" |
550 | | "Return the hexadecimal representation of an integer.\n" |
551 | | "\n" |
552 | | " >>> hex(12648430)\n" |
553 | | " \'0xc0ffee\'"); |
554 | | |
555 | | #define BUILTIN_HEX_METHODDEF \ |
556 | | {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__}, |
557 | | |
558 | | PyDoc_STRVAR(builtin_len__doc__, |
559 | | "len($module, obj, /)\n" |
560 | | "--\n" |
561 | | "\n" |
562 | | "Return the number of items in a container."); |
563 | | |
564 | | #define BUILTIN_LEN_METHODDEF \ |
565 | | {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__}, |
566 | | |
567 | | PyDoc_STRVAR(builtin_locals__doc__, |
568 | | "locals($module, /)\n" |
569 | | "--\n" |
570 | | "\n" |
571 | | "Return a dictionary containing the current scope\'s local variables.\n" |
572 | | "\n" |
573 | | "NOTE: Whether or not updates to this dictionary will affect name lookups in\n" |
574 | | "the local scope and vice-versa is *implementation dependent* and not\n" |
575 | | "covered by any backwards compatibility guarantees."); |
576 | | |
577 | | #define BUILTIN_LOCALS_METHODDEF \ |
578 | | {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__}, |
579 | | |
580 | | static PyObject * |
581 | | builtin_locals_impl(PyObject *module); |
582 | | |
583 | | static PyObject * |
584 | | builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
585 | 0 | { |
586 | 0 | return builtin_locals_impl(module); |
587 | 0 | } |
588 | | |
589 | | PyDoc_STRVAR(builtin_oct__doc__, |
590 | | "oct($module, number, /)\n" |
591 | | "--\n" |
592 | | "\n" |
593 | | "Return the octal representation of an integer.\n" |
594 | | "\n" |
595 | | " >>> oct(342391)\n" |
596 | | " \'0o1234567\'"); |
597 | | |
598 | | #define BUILTIN_OCT_METHODDEF \ |
599 | | {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__}, |
600 | | |
601 | | PyDoc_STRVAR(builtin_ord__doc__, |
602 | | "ord($module, c, /)\n" |
603 | | "--\n" |
604 | | "\n" |
605 | | "Return the Unicode code point for a one-character string."); |
606 | | |
607 | | #define BUILTIN_ORD_METHODDEF \ |
608 | | {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__}, |
609 | | |
610 | | PyDoc_STRVAR(builtin_pow__doc__, |
611 | | "pow($module, /, base, exp, mod=None)\n" |
612 | | "--\n" |
613 | | "\n" |
614 | | "Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments\n" |
615 | | "\n" |
616 | | "Some types, such as ints, are able to use a more efficient algorithm when\n" |
617 | | "invoked using the three argument form."); |
618 | | |
619 | | #define BUILTIN_POW_METHODDEF \ |
620 | | {"pow", (PyCFunction)(void(*)(void))builtin_pow, METH_FASTCALL|METH_KEYWORDS, builtin_pow__doc__}, |
621 | | |
622 | | static PyObject * |
623 | | builtin_pow_impl(PyObject *module, PyObject *base, PyObject *exp, |
624 | | PyObject *mod); |
625 | | |
626 | | static PyObject * |
627 | | builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
628 | 0 | { |
629 | 0 | PyObject *return_value = NULL; |
630 | 0 | static const char * const _keywords[] = {"base", "exp", "mod", NULL}; |
631 | 0 | static _PyArg_Parser _parser = {NULL, _keywords, "pow", 0}; |
632 | 0 | PyObject *argsbuf[3]; |
633 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
634 | 0 | PyObject *base; |
635 | 0 | PyObject *exp; |
636 | 0 | PyObject *mod = Py_None; |
637 | |
|
638 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
639 | 0 | if (!args) { |
640 | 0 | goto exit; |
641 | 0 | } |
642 | 0 | base = args[0]; |
643 | 0 | exp = args[1]; |
644 | 0 | if (!noptargs) { |
645 | 0 | goto skip_optional_pos; |
646 | 0 | } |
647 | 0 | mod = args[2]; |
648 | 0 | skip_optional_pos: |
649 | 0 | return_value = builtin_pow_impl(module, base, exp, mod); |
650 | |
|
651 | 0 | exit: |
652 | 0 | return return_value; |
653 | 0 | } |
654 | | |
655 | | PyDoc_STRVAR(builtin_input__doc__, |
656 | | "input($module, prompt=None, /)\n" |
657 | | "--\n" |
658 | | "\n" |
659 | | "Read a string from standard input. The trailing newline is stripped.\n" |
660 | | "\n" |
661 | | "The prompt string, if given, is printed to standard output without a\n" |
662 | | "trailing newline before reading input.\n" |
663 | | "\n" |
664 | | "If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n" |
665 | | "On *nix systems, readline is used if available."); |
666 | | |
667 | | #define BUILTIN_INPUT_METHODDEF \ |
668 | | {"input", (PyCFunction)(void(*)(void))builtin_input, METH_FASTCALL, builtin_input__doc__}, |
669 | | |
670 | | static PyObject * |
671 | | builtin_input_impl(PyObject *module, PyObject *prompt); |
672 | | |
673 | | static PyObject * |
674 | | builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
675 | 0 | { |
676 | 0 | PyObject *return_value = NULL; |
677 | 0 | PyObject *prompt = NULL; |
678 | |
|
679 | 0 | if (!_PyArg_CheckPositional("input", nargs, 0, 1)) { |
680 | 0 | goto exit; |
681 | 0 | } |
682 | 0 | if (nargs < 1) { |
683 | 0 | goto skip_optional; |
684 | 0 | } |
685 | 0 | prompt = args[0]; |
686 | 0 | skip_optional: |
687 | 0 | return_value = builtin_input_impl(module, prompt); |
688 | |
|
689 | 0 | exit: |
690 | 0 | return return_value; |
691 | 0 | } |
692 | | |
693 | | PyDoc_STRVAR(builtin_repr__doc__, |
694 | | "repr($module, obj, /)\n" |
695 | | "--\n" |
696 | | "\n" |
697 | | "Return the canonical string representation of the object.\n" |
698 | | "\n" |
699 | | "For many object types, including most builtins, eval(repr(obj)) == obj."); |
700 | | |
701 | | #define BUILTIN_REPR_METHODDEF \ |
702 | | {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__}, |
703 | | |
704 | | PyDoc_STRVAR(builtin_round__doc__, |
705 | | "round($module, /, number, ndigits=None)\n" |
706 | | "--\n" |
707 | | "\n" |
708 | | "Round a number to a given precision in decimal digits.\n" |
709 | | "\n" |
710 | | "The return value is an integer if ndigits is omitted or None. Otherwise\n" |
711 | | "the return value has the same type as the number. ndigits may be negative."); |
712 | | |
713 | | #define BUILTIN_ROUND_METHODDEF \ |
714 | | {"round", (PyCFunction)(void(*)(void))builtin_round, METH_FASTCALL|METH_KEYWORDS, builtin_round__doc__}, |
715 | | |
716 | | static PyObject * |
717 | | builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits); |
718 | | |
719 | | static PyObject * |
720 | | builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
721 | 0 | { |
722 | 0 | PyObject *return_value = NULL; |
723 | 0 | static const char * const _keywords[] = {"number", "ndigits", NULL}; |
724 | 0 | static _PyArg_Parser _parser = {NULL, _keywords, "round", 0}; |
725 | 0 | PyObject *argsbuf[2]; |
726 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
727 | 0 | PyObject *number; |
728 | 0 | PyObject *ndigits = Py_None; |
729 | |
|
730 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
731 | 0 | if (!args) { |
732 | 0 | goto exit; |
733 | 0 | } |
734 | 0 | number = args[0]; |
735 | 0 | if (!noptargs) { |
736 | 0 | goto skip_optional_pos; |
737 | 0 | } |
738 | 0 | ndigits = args[1]; |
739 | 0 | skip_optional_pos: |
740 | 0 | return_value = builtin_round_impl(module, number, ndigits); |
741 | |
|
742 | 0 | exit: |
743 | 0 | return return_value; |
744 | 0 | } |
745 | | |
746 | | PyDoc_STRVAR(builtin_sum__doc__, |
747 | | "sum($module, iterable, /, start=0)\n" |
748 | | "--\n" |
749 | | "\n" |
750 | | "Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n" |
751 | | "\n" |
752 | | "When the iterable is empty, return the start value.\n" |
753 | | "This function is intended specifically for use with numeric values and may\n" |
754 | | "reject non-numeric types."); |
755 | | |
756 | | #define BUILTIN_SUM_METHODDEF \ |
757 | | {"sum", (PyCFunction)(void(*)(void))builtin_sum, METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__}, |
758 | | |
759 | | static PyObject * |
760 | | builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start); |
761 | | |
762 | | static PyObject * |
763 | | builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
764 | 0 | { |
765 | 0 | PyObject *return_value = NULL; |
766 | 0 | static const char * const _keywords[] = {"", "start", NULL}; |
767 | 0 | static _PyArg_Parser _parser = {NULL, _keywords, "sum", 0}; |
768 | 0 | PyObject *argsbuf[2]; |
769 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
770 | 0 | PyObject *iterable; |
771 | 0 | PyObject *start = NULL; |
772 | |
|
773 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
774 | 0 | if (!args) { |
775 | 0 | goto exit; |
776 | 0 | } |
777 | 0 | iterable = args[0]; |
778 | 0 | if (!noptargs) { |
779 | 0 | goto skip_optional_pos; |
780 | 0 | } |
781 | 0 | start = args[1]; |
782 | 0 | skip_optional_pos: |
783 | 0 | return_value = builtin_sum_impl(module, iterable, start); |
784 | |
|
785 | 0 | exit: |
786 | 0 | return return_value; |
787 | 0 | } |
788 | | |
789 | | PyDoc_STRVAR(builtin_isinstance__doc__, |
790 | | "isinstance($module, obj, class_or_tuple, /)\n" |
791 | | "--\n" |
792 | | "\n" |
793 | | "Return whether an object is an instance of a class or of a subclass thereof.\n" |
794 | | "\n" |
795 | | "A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n" |
796 | | "check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n" |
797 | | "or ...`` etc."); |
798 | | |
799 | | #define BUILTIN_ISINSTANCE_METHODDEF \ |
800 | | {"isinstance", (PyCFunction)(void(*)(void))builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__}, |
801 | | |
802 | | static PyObject * |
803 | | builtin_isinstance_impl(PyObject *module, PyObject *obj, |
804 | | PyObject *class_or_tuple); |
805 | | |
806 | | static PyObject * |
807 | | builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
808 | 2.63k | { |
809 | 2.63k | PyObject *return_value = NULL; |
810 | 2.63k | PyObject *obj; |
811 | 2.63k | PyObject *class_or_tuple; |
812 | | |
813 | 2.63k | if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) { |
814 | 0 | goto exit; |
815 | 0 | } |
816 | 2.63k | obj = args[0]; |
817 | 2.63k | class_or_tuple = args[1]; |
818 | 2.63k | return_value = builtin_isinstance_impl(module, obj, class_or_tuple); |
819 | | |
820 | 2.63k | exit: |
821 | 2.63k | return return_value; |
822 | 2.63k | } |
823 | | |
824 | | PyDoc_STRVAR(builtin_issubclass__doc__, |
825 | | "issubclass($module, cls, class_or_tuple, /)\n" |
826 | | "--\n" |
827 | | "\n" |
828 | | "Return whether \'cls\' is a derived from another class or is the same class.\n" |
829 | | "\n" |
830 | | "A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n" |
831 | | "check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n" |
832 | | "or ...`` etc."); |
833 | | |
834 | | #define BUILTIN_ISSUBCLASS_METHODDEF \ |
835 | | {"issubclass", (PyCFunction)(void(*)(void))builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__}, |
836 | | |
837 | | static PyObject * |
838 | | builtin_issubclass_impl(PyObject *module, PyObject *cls, |
839 | | PyObject *class_or_tuple); |
840 | | |
841 | | static PyObject * |
842 | | builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
843 | 46 | { |
844 | 46 | PyObject *return_value = NULL; |
845 | 46 | PyObject *cls; |
846 | 46 | PyObject *class_or_tuple; |
847 | | |
848 | 46 | if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) { |
849 | 0 | goto exit; |
850 | 0 | } |
851 | 46 | cls = args[0]; |
852 | 46 | class_or_tuple = args[1]; |
853 | 46 | return_value = builtin_issubclass_impl(module, cls, class_or_tuple); |
854 | | |
855 | 46 | exit: |
856 | 46 | return return_value; |
857 | 46 | } |
858 | | /*[clinic end generated code: output=29686a89b739d600 input=a9049054013a1b77]*/ |