blob: b52bde26124283fcec6ad0d4bc5ed87a29f84669 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
14PyDoc_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
25PyDoc_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
36PyDoc_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
50PyDoc_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
62PyDoc_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
74PyDoc_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");
81
82#define BUILTIN_FORMAT_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010083 {"format", (PyCFunction)builtin_format, METH_FASTCALL, builtin_format__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030084
85static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030086builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030087
88static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +010089builtin_format(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030090{
91 PyObject *return_value = NULL;
92 PyObject *value;
93 PyObject *format_spec = NULL;
94
Victor Stinner259f0e42017-01-17 01:35:17 +010095 if (!_PyArg_ParseStack(args, nargs, "O|U:format",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030096 &value, &format_spec)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030097 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030098 }
Victor Stinner259f0e42017-01-17 01:35:17 +010099
100 if (!_PyArg_NoStackKeywords("format", kwnames)) {
101 goto exit;
102 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300103 return_value = builtin_format_impl(module, value, format_spec);
104
105exit:
106 return return_value;
107}
108
109PyDoc_STRVAR(builtin_chr__doc__,
110"chr($module, i, /)\n"
111"--\n"
112"\n"
113"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
114
115#define BUILTIN_CHR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300116 {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300117
118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300119builtin_chr_impl(PyObject *module, int i);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300120
121static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300122builtin_chr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300123{
124 PyObject *return_value = NULL;
125 int i;
126
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300127 if (!PyArg_Parse(arg, "i:chr", &i)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300128 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300129 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130 return_value = builtin_chr_impl(module, i);
131
132exit:
133 return return_value;
134}
135
136PyDoc_STRVAR(builtin_compile__doc__,
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300137"compile($module, /, source, filename, mode, flags=0,\n"
138" dont_inherit=False, optimize=-1)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300139"--\n"
140"\n"
141"Compile source into a code object that can be executed by exec() or eval().\n"
142"\n"
143"The source code may represent a Python module, statement or expression.\n"
144"The filename will be used for run-time error messages.\n"
145"The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
146"single (interactive) statement, or \'eval\' to compile an expression.\n"
147"The flags argument, if present, controls which future statements influence\n"
148"the compilation of the code.\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300149"The dont_inherit argument, if true, stops the compilation inheriting\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150"the effects of any future statements in effect in the code calling\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300151"compile; if absent or false these statements do influence the compilation,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152"in addition to any features explicitly specified.");
153
154#define BUILTIN_COMPILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700155 {"compile", (PyCFunction)builtin_compile, METH_FASTCALL, builtin_compile__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156
157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300158builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
159 const char *mode, int flags, int dont_inherit,
160 int optimize);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300161
162static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700163builtin_compile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300164{
165 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300166 static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL};
167 static _PyArg_Parser _parser = {"OO&s|iii:compile", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300168 PyObject *source;
169 PyObject *filename;
170 const char *mode;
171 int flags = 0;
172 int dont_inherit = 0;
173 int optimize = -1;
174
Victor Stinner3e1fad62017-01-17 01:29:01 +0100175 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300176 &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300177 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300178 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300179 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize);
180
181exit:
182 return return_value;
183}
184
185PyDoc_STRVAR(builtin_divmod__doc__,
186"divmod($module, x, y, /)\n"
187"--\n"
188"\n"
Serhiy Storchakadf071732016-05-01 20:33:24 +0300189"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300190
191#define BUILTIN_DIVMOD_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100192 {"divmod", (PyCFunction)builtin_divmod, METH_FASTCALL, builtin_divmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300193
194static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300195builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300196
197static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100198builtin_divmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300199{
200 PyObject *return_value = NULL;
201 PyObject *x;
202 PyObject *y;
203
Victor Stinner0c4a8282017-01-17 02:21:47 +0100204 if (!_PyArg_UnpackStack(args, nargs, "divmod",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300205 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300206 &x, &y)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300207 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300208 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100209
210 if (!_PyArg_NoStackKeywords("divmod", kwnames)) {
211 goto exit;
212 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300213 return_value = builtin_divmod_impl(module, x, y);
214
215exit:
216 return return_value;
217}
218
219PyDoc_STRVAR(builtin_eval__doc__,
220"eval($module, source, globals=None, locals=None, /)\n"
221"--\n"
222"\n"
223"Evaluate the given source in the context of globals and locals.\n"
224"\n"
225"The source may be a string representing a Python expression\n"
226"or a code object as returned by compile().\n"
227"The globals must be a dictionary and locals can be any mapping,\n"
228"defaulting to the current globals and locals.\n"
229"If only globals is given, locals defaults to it.");
230
231#define BUILTIN_EVAL_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100232 {"eval", (PyCFunction)builtin_eval, METH_FASTCALL, builtin_eval__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300233
234static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300235builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400236 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300237
238static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100239builtin_eval(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300240{
241 PyObject *return_value = NULL;
242 PyObject *source;
243 PyObject *globals = Py_None;
244 PyObject *locals = Py_None;
245
Victor Stinner0c4a8282017-01-17 02:21:47 +0100246 if (!_PyArg_UnpackStack(args, nargs, "eval",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300247 1, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300248 &source, &globals, &locals)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300249 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300250 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100251
252 if (!_PyArg_NoStackKeywords("eval", kwnames)) {
253 goto exit;
254 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300255 return_value = builtin_eval_impl(module, source, globals, locals);
256
257exit:
258 return return_value;
259}
260
261PyDoc_STRVAR(builtin_exec__doc__,
262"exec($module, source, globals=None, locals=None, /)\n"
263"--\n"
264"\n"
265"Execute the given source in the context of globals and locals.\n"
266"\n"
267"The source may be a string representing one or more Python statements\n"
268"or a code object as returned by compile().\n"
269"The globals must be a dictionary and locals can be any mapping,\n"
270"defaulting to the current globals and locals.\n"
271"If only globals is given, locals defaults to it.");
272
273#define BUILTIN_EXEC_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100274 {"exec", (PyCFunction)builtin_exec, METH_FASTCALL, builtin_exec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300275
276static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300277builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400278 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300279
280static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100281builtin_exec(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300282{
283 PyObject *return_value = NULL;
284 PyObject *source;
285 PyObject *globals = Py_None;
286 PyObject *locals = Py_None;
287
Victor Stinner0c4a8282017-01-17 02:21:47 +0100288 if (!_PyArg_UnpackStack(args, nargs, "exec",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300289 1, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300290 &source, &globals, &locals)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300291 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300292 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100293
294 if (!_PyArg_NoStackKeywords("exec", kwnames)) {
295 goto exit;
296 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300297 return_value = builtin_exec_impl(module, source, globals, locals);
298
299exit:
300 return return_value;
301}
302
303PyDoc_STRVAR(builtin_globals__doc__,
304"globals($module, /)\n"
305"--\n"
306"\n"
307"Return the dictionary containing the current scope\'s global variables.\n"
308"\n"
309"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
310"global scope and vice-versa.");
311
312#define BUILTIN_GLOBALS_METHODDEF \
313 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
314
315static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300316builtin_globals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300317
318static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300319builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300320{
321 return builtin_globals_impl(module);
322}
323
324PyDoc_STRVAR(builtin_hasattr__doc__,
325"hasattr($module, obj, name, /)\n"
326"--\n"
327"\n"
328"Return whether the object has an attribute with the given name.\n"
329"\n"
330"This is done by calling getattr(obj, name) and catching AttributeError.");
331
332#define BUILTIN_HASATTR_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100333 {"hasattr", (PyCFunction)builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300334
335static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300336builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300337
338static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100339builtin_hasattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300340{
341 PyObject *return_value = NULL;
342 PyObject *obj;
343 PyObject *name;
344
Victor Stinner0c4a8282017-01-17 02:21:47 +0100345 if (!_PyArg_UnpackStack(args, nargs, "hasattr",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300347 &obj, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300348 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300349 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100350
351 if (!_PyArg_NoStackKeywords("hasattr", kwnames)) {
352 goto exit;
353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300354 return_value = builtin_hasattr_impl(module, obj, name);
355
356exit:
357 return return_value;
358}
359
360PyDoc_STRVAR(builtin_id__doc__,
361"id($module, obj, /)\n"
362"--\n"
363"\n"
364"Return the identity of an object.\n"
365"\n"
366"This is guaranteed to be unique among simultaneously existing objects.\n"
367"(CPython uses the object\'s memory address.)");
368
369#define BUILTIN_ID_METHODDEF \
370 {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
371
372PyDoc_STRVAR(builtin_setattr__doc__,
373"setattr($module, obj, name, value, /)\n"
374"--\n"
375"\n"
376"Sets the named attribute on the given object to the specified value.\n"
377"\n"
378"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
379
380#define BUILTIN_SETATTR_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100381 {"setattr", (PyCFunction)builtin_setattr, METH_FASTCALL, builtin_setattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300382
383static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300384builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
Larry Hastings89964c42015-04-14 18:07:59 -0400385 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300386
387static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100388builtin_setattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300389{
390 PyObject *return_value = NULL;
391 PyObject *obj;
392 PyObject *name;
393 PyObject *value;
394
Victor Stinner0c4a8282017-01-17 02:21:47 +0100395 if (!_PyArg_UnpackStack(args, nargs, "setattr",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300396 3, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300397 &obj, &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300398 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300399 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100400
401 if (!_PyArg_NoStackKeywords("setattr", kwnames)) {
402 goto exit;
403 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300404 return_value = builtin_setattr_impl(module, obj, name, value);
405
406exit:
407 return return_value;
408}
409
410PyDoc_STRVAR(builtin_delattr__doc__,
411"delattr($module, obj, name, /)\n"
412"--\n"
413"\n"
414"Deletes the named attribute from the given object.\n"
415"\n"
416"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
417
418#define BUILTIN_DELATTR_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100419 {"delattr", (PyCFunction)builtin_delattr, METH_FASTCALL, builtin_delattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300420
421static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300422builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300423
424static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100425builtin_delattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300426{
427 PyObject *return_value = NULL;
428 PyObject *obj;
429 PyObject *name;
430
Victor Stinner0c4a8282017-01-17 02:21:47 +0100431 if (!_PyArg_UnpackStack(args, nargs, "delattr",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300432 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300433 &obj, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300434 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300435 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100436
437 if (!_PyArg_NoStackKeywords("delattr", kwnames)) {
438 goto exit;
439 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300440 return_value = builtin_delattr_impl(module, obj, name);
441
442exit:
443 return return_value;
444}
445
446PyDoc_STRVAR(builtin_hash__doc__,
447"hash($module, obj, /)\n"
448"--\n"
449"\n"
450"Return the hash value for the given object.\n"
451"\n"
452"Two objects that compare equal must also have the same hash value, but the\n"
453"reverse is not necessarily true.");
454
455#define BUILTIN_HASH_METHODDEF \
456 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
457
458PyDoc_STRVAR(builtin_hex__doc__,
459"hex($module, number, /)\n"
460"--\n"
461"\n"
462"Return the hexadecimal representation of an integer.\n"
463"\n"
464" >>> hex(12648430)\n"
465" \'0xc0ffee\'");
466
467#define BUILTIN_HEX_METHODDEF \
468 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
469
470PyDoc_STRVAR(builtin_len__doc__,
471"len($module, obj, /)\n"
472"--\n"
473"\n"
474"Return the number of items in a container.");
475
476#define BUILTIN_LEN_METHODDEF \
477 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
478
479PyDoc_STRVAR(builtin_locals__doc__,
480"locals($module, /)\n"
481"--\n"
482"\n"
483"Return a dictionary containing the current scope\'s local variables.\n"
484"\n"
485"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
486"the local scope and vice-versa is *implementation dependent* and not\n"
487"covered by any backwards compatibility guarantees.");
488
489#define BUILTIN_LOCALS_METHODDEF \
490 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
491
492static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300493builtin_locals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300494
495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300496builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300497{
498 return builtin_locals_impl(module);
499}
500
501PyDoc_STRVAR(builtin_oct__doc__,
502"oct($module, number, /)\n"
503"--\n"
504"\n"
505"Return the octal representation of an integer.\n"
506"\n"
507" >>> oct(342391)\n"
508" \'0o1234567\'");
509
510#define BUILTIN_OCT_METHODDEF \
511 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
512
513PyDoc_STRVAR(builtin_ord__doc__,
514"ord($module, c, /)\n"
515"--\n"
516"\n"
517"Return the Unicode code point for a one-character string.");
518
519#define BUILTIN_ORD_METHODDEF \
520 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
521
522PyDoc_STRVAR(builtin_pow__doc__,
523"pow($module, x, y, z=None, /)\n"
524"--\n"
525"\n"
526"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
527"\n"
528"Some types, such as ints, are able to use a more efficient algorithm when\n"
529"invoked using the three argument form.");
530
531#define BUILTIN_POW_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100532 {"pow", (PyCFunction)builtin_pow, METH_FASTCALL, builtin_pow__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300533
534static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300535builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300536
537static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100538builtin_pow(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300539{
540 PyObject *return_value = NULL;
541 PyObject *x;
542 PyObject *y;
543 PyObject *z = Py_None;
544
Victor Stinner0c4a8282017-01-17 02:21:47 +0100545 if (!_PyArg_UnpackStack(args, nargs, "pow",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300546 2, 3,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300547 &x, &y, &z)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300549 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100550
551 if (!_PyArg_NoStackKeywords("pow", kwnames)) {
552 goto exit;
553 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300554 return_value = builtin_pow_impl(module, x, y, z);
555
556exit:
557 return return_value;
558}
559
560PyDoc_STRVAR(builtin_input__doc__,
561"input($module, prompt=None, /)\n"
562"--\n"
563"\n"
564"Read a string from standard input. The trailing newline is stripped.\n"
565"\n"
566"The prompt string, if given, is printed to standard output without a\n"
567"trailing newline before reading input.\n"
568"\n"
569"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
570"On *nix systems, readline is used if available.");
571
572#define BUILTIN_INPUT_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100573 {"input", (PyCFunction)builtin_input, METH_FASTCALL, builtin_input__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300574
575static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300576builtin_input_impl(PyObject *module, PyObject *prompt);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300577
578static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100579builtin_input(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300580{
581 PyObject *return_value = NULL;
582 PyObject *prompt = NULL;
583
Victor Stinner0c4a8282017-01-17 02:21:47 +0100584 if (!_PyArg_UnpackStack(args, nargs, "input",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300585 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300586 &prompt)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300587 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300588 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100589
590 if (!_PyArg_NoStackKeywords("input", kwnames)) {
591 goto exit;
592 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300593 return_value = builtin_input_impl(module, prompt);
594
595exit:
596 return return_value;
597}
598
599PyDoc_STRVAR(builtin_repr__doc__,
600"repr($module, obj, /)\n"
601"--\n"
602"\n"
603"Return the canonical string representation of the object.\n"
604"\n"
605"For many object types, including most builtins, eval(repr(obj)) == obj.");
606
607#define BUILTIN_REPR_METHODDEF \
608 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
609
610PyDoc_STRVAR(builtin_sum__doc__,
611"sum($module, iterable, start=0, /)\n"
612"--\n"
613"\n"
614"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
615"\n"
616"When the iterable is empty, return the start value.\n"
617"This function is intended specifically for use with numeric values and may\n"
618"reject non-numeric types.");
619
620#define BUILTIN_SUM_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100621 {"sum", (PyCFunction)builtin_sum, METH_FASTCALL, builtin_sum__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300622
623static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300624builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300625
626static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100627builtin_sum(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300628{
629 PyObject *return_value = NULL;
630 PyObject *iterable;
631 PyObject *start = NULL;
632
Victor Stinner0c4a8282017-01-17 02:21:47 +0100633 if (!_PyArg_UnpackStack(args, nargs, "sum",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300634 1, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300635 &iterable, &start)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300636 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300637 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100638
639 if (!_PyArg_NoStackKeywords("sum", kwnames)) {
640 goto exit;
641 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300642 return_value = builtin_sum_impl(module, iterable, start);
643
644exit:
645 return return_value;
646}
647
648PyDoc_STRVAR(builtin_isinstance__doc__,
649"isinstance($module, obj, class_or_tuple, /)\n"
650"--\n"
651"\n"
652"Return whether an object is an instance of a class or of a subclass thereof.\n"
653"\n"
654"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
655"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
656"or ...`` etc.");
657
658#define BUILTIN_ISINSTANCE_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100659 {"isinstance", (PyCFunction)builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300660
661static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300662builtin_isinstance_impl(PyObject *module, PyObject *obj,
Larry Hastings89964c42015-04-14 18:07:59 -0400663 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300664
665static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100666builtin_isinstance(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300667{
668 PyObject *return_value = NULL;
669 PyObject *obj;
670 PyObject *class_or_tuple;
671
Victor Stinner0c4a8282017-01-17 02:21:47 +0100672 if (!_PyArg_UnpackStack(args, nargs, "isinstance",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300673 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300674 &obj, &class_or_tuple)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300675 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300676 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100677
678 if (!_PyArg_NoStackKeywords("isinstance", kwnames)) {
679 goto exit;
680 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300681 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
682
683exit:
684 return return_value;
685}
686
687PyDoc_STRVAR(builtin_issubclass__doc__,
688"issubclass($module, cls, class_or_tuple, /)\n"
689"--\n"
690"\n"
691"Return whether \'cls\' is a derived from another class or is the same class.\n"
692"\n"
693"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
694"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
695"or ...`` etc.");
696
697#define BUILTIN_ISSUBCLASS_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100698 {"issubclass", (PyCFunction)builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300699
700static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300701builtin_issubclass_impl(PyObject *module, PyObject *cls,
Larry Hastings89964c42015-04-14 18:07:59 -0400702 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300703
704static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100705builtin_issubclass(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300706{
707 PyObject *return_value = NULL;
708 PyObject *cls;
709 PyObject *class_or_tuple;
710
Victor Stinner0c4a8282017-01-17 02:21:47 +0100711 if (!_PyArg_UnpackStack(args, nargs, "issubclass",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300712 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300713 &cls, &class_or_tuple)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300714 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300715 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100716
717 if (!_PyArg_NoStackKeywords("issubclass", kwnames)) {
718 goto exit;
719 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300720 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
721
722exit:
723 return return_value;
724}
Victor Stinner0c4a8282017-01-17 02:21:47 +0100725/*[clinic end generated code: output=3234725ef4d8bbf1 input=a9049054013a1b77]*/