blob: 0e46f94feacd85f023b6db59b6638736654de49e [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"
Amit Kumar2e6bb442017-05-29 06:32:26 +053080"format_spec defaults to the empty string.\n"
81"See the Format Specification Mini-Language section of help(\'FORMATTING\') for\n"
82"details.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030083
84#define BUILTIN_FORMAT_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010085 {"format", (PyCFunction)builtin_format, METH_FASTCALL, builtin_format__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030086
87static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030088builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030089
90static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +010091builtin_format(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030092{
93 PyObject *return_value = NULL;
94 PyObject *value;
95 PyObject *format_spec = NULL;
96
Sylvain74453812017-06-10 06:51:48 +020097 if (!_PyArg_NoStackKeywords("format", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030098 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030099 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100100
Sylvain74453812017-06-10 06:51:48 +0200101 if (!_PyArg_ParseStack(args, nargs, "O|U:format",
102 &value, &format_spec)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100103 goto exit;
104 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300105 return_value = builtin_format_impl(module, value, format_spec);
106
107exit:
108 return return_value;
109}
110
111PyDoc_STRVAR(builtin_chr__doc__,
112"chr($module, i, /)\n"
113"--\n"
114"\n"
115"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
116
117#define BUILTIN_CHR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300118 {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300119
120static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300121builtin_chr_impl(PyObject *module, int i);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300122
123static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300124builtin_chr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300125{
126 PyObject *return_value = NULL;
127 int i;
128
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300129 if (!PyArg_Parse(arg, "i:chr", &i)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300131 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300132 return_value = builtin_chr_impl(module, i);
133
134exit:
135 return return_value;
136}
137
138PyDoc_STRVAR(builtin_compile__doc__,
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300139"compile($module, /, source, filename, mode, flags=0,\n"
140" dont_inherit=False, optimize=-1)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300141"--\n"
142"\n"
143"Compile source into a code object that can be executed by exec() or eval().\n"
144"\n"
145"The source code may represent a Python module, statement or expression.\n"
146"The filename will be used for run-time error messages.\n"
147"The mode must be \'exec\' to compile a module, \'single\' to compile a\n"
148"single (interactive) statement, or \'eval\' to compile an expression.\n"
149"The flags argument, if present, controls which future statements influence\n"
150"the compilation of the code.\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300151"The dont_inherit argument, if true, stops the compilation inheriting\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152"the effects of any future statements in effect in the code calling\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300153"compile; if absent or false these statements do influence the compilation,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154"in addition to any features explicitly specified.");
155
156#define BUILTIN_COMPILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700157 {"compile", (PyCFunction)builtin_compile, METH_FASTCALL, builtin_compile__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300158
159static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300160builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
161 const char *mode, int flags, int dont_inherit,
162 int optimize);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300163
164static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700165builtin_compile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300166{
167 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300168 static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL};
169 static _PyArg_Parser _parser = {"OO&s|iii:compile", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300170 PyObject *source;
171 PyObject *filename;
172 const char *mode;
173 int flags = 0;
174 int dont_inherit = 0;
175 int optimize = -1;
176
Victor Stinner3e1fad62017-01-17 01:29:01 +0100177 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300178 &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300179 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300180 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize);
182
183exit:
184 return return_value;
185}
186
187PyDoc_STRVAR(builtin_divmod__doc__,
188"divmod($module, x, y, /)\n"
189"--\n"
190"\n"
Serhiy Storchakadf071732016-05-01 20:33:24 +0300191"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192
193#define BUILTIN_DIVMOD_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100194 {"divmod", (PyCFunction)builtin_divmod, METH_FASTCALL, builtin_divmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300195
196static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300197builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300198
199static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100200builtin_divmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300201{
202 PyObject *return_value = NULL;
203 PyObject *x;
204 PyObject *y;
205
Sylvain74453812017-06-10 06:51:48 +0200206 if (!_PyArg_NoStackKeywords("divmod", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200210 if (!_PyArg_UnpackStack(args, nargs, "divmod",
211 2, 2,
212 &x, &y)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100213 goto exit;
214 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300215 return_value = builtin_divmod_impl(module, x, y);
216
217exit:
218 return return_value;
219}
220
221PyDoc_STRVAR(builtin_eval__doc__,
222"eval($module, source, globals=None, locals=None, /)\n"
223"--\n"
224"\n"
225"Evaluate the given source in the context of globals and locals.\n"
226"\n"
227"The source may be a string representing a Python expression\n"
228"or a code object as returned by compile().\n"
229"The globals must be a dictionary and locals can be any mapping,\n"
230"defaulting to the current globals and locals.\n"
231"If only globals is given, locals defaults to it.");
232
233#define BUILTIN_EVAL_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100234 {"eval", (PyCFunction)builtin_eval, METH_FASTCALL, builtin_eval__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300235
236static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300237builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400238 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300239
240static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100241builtin_eval(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300242{
243 PyObject *return_value = NULL;
244 PyObject *source;
245 PyObject *globals = Py_None;
246 PyObject *locals = Py_None;
247
Sylvain74453812017-06-10 06:51:48 +0200248 if (!_PyArg_NoStackKeywords("eval", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200252 if (!_PyArg_UnpackStack(args, nargs, "eval",
253 1, 3,
254 &source, &globals, &locals)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100255 goto exit;
256 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300257 return_value = builtin_eval_impl(module, source, globals, locals);
258
259exit:
260 return return_value;
261}
262
263PyDoc_STRVAR(builtin_exec__doc__,
264"exec($module, source, globals=None, locals=None, /)\n"
265"--\n"
266"\n"
267"Execute the given source in the context of globals and locals.\n"
268"\n"
269"The source may be a string representing one or more Python statements\n"
270"or a code object as returned by compile().\n"
271"The globals must be a dictionary and locals can be any mapping,\n"
272"defaulting to the current globals and locals.\n"
273"If only globals is given, locals defaults to it.");
274
275#define BUILTIN_EXEC_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100276 {"exec", (PyCFunction)builtin_exec, METH_FASTCALL, builtin_exec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300277
278static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300279builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400280 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300281
282static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100283builtin_exec(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300284{
285 PyObject *return_value = NULL;
286 PyObject *source;
287 PyObject *globals = Py_None;
288 PyObject *locals = Py_None;
289
Sylvain74453812017-06-10 06:51:48 +0200290 if (!_PyArg_NoStackKeywords("exec", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200294 if (!_PyArg_UnpackStack(args, nargs, "exec",
295 1, 3,
296 &source, &globals, &locals)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100297 goto exit;
298 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300299 return_value = builtin_exec_impl(module, source, globals, locals);
300
301exit:
302 return return_value;
303}
304
305PyDoc_STRVAR(builtin_globals__doc__,
306"globals($module, /)\n"
307"--\n"
308"\n"
309"Return the dictionary containing the current scope\'s global variables.\n"
310"\n"
311"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
312"global scope and vice-versa.");
313
314#define BUILTIN_GLOBALS_METHODDEF \
315 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
316
317static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300318builtin_globals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300319
320static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300321builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300322{
323 return builtin_globals_impl(module);
324}
325
326PyDoc_STRVAR(builtin_hasattr__doc__,
327"hasattr($module, obj, name, /)\n"
328"--\n"
329"\n"
330"Return whether the object has an attribute with the given name.\n"
331"\n"
332"This is done by calling getattr(obj, name) and catching AttributeError.");
333
334#define BUILTIN_HASATTR_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100335 {"hasattr", (PyCFunction)builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300336
337static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300338builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300339
340static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100341builtin_hasattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300342{
343 PyObject *return_value = NULL;
344 PyObject *obj;
345 PyObject *name;
346
Sylvain74453812017-06-10 06:51:48 +0200347 if (!_PyArg_NoStackKeywords("hasattr", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200351 if (!_PyArg_UnpackStack(args, nargs, "hasattr",
352 2, 2,
353 &obj, &name)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100354 goto exit;
355 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300356 return_value = builtin_hasattr_impl(module, obj, name);
357
358exit:
359 return return_value;
360}
361
362PyDoc_STRVAR(builtin_id__doc__,
363"id($module, obj, /)\n"
364"--\n"
365"\n"
366"Return the identity of an object.\n"
367"\n"
368"This is guaranteed to be unique among simultaneously existing objects.\n"
369"(CPython uses the object\'s memory address.)");
370
371#define BUILTIN_ID_METHODDEF \
372 {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
373
374PyDoc_STRVAR(builtin_setattr__doc__,
375"setattr($module, obj, name, value, /)\n"
376"--\n"
377"\n"
378"Sets the named attribute on the given object to the specified value.\n"
379"\n"
380"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
381
382#define BUILTIN_SETATTR_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100383 {"setattr", (PyCFunction)builtin_setattr, METH_FASTCALL, builtin_setattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300384
385static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300386builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
Larry Hastings89964c42015-04-14 18:07:59 -0400387 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300388
389static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100390builtin_setattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300391{
392 PyObject *return_value = NULL;
393 PyObject *obj;
394 PyObject *name;
395 PyObject *value;
396
Sylvain74453812017-06-10 06:51:48 +0200397 if (!_PyArg_NoStackKeywords("setattr", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200401 if (!_PyArg_UnpackStack(args, nargs, "setattr",
402 3, 3,
403 &obj, &name, &value)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100404 goto exit;
405 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300406 return_value = builtin_setattr_impl(module, obj, name, value);
407
408exit:
409 return return_value;
410}
411
412PyDoc_STRVAR(builtin_delattr__doc__,
413"delattr($module, obj, name, /)\n"
414"--\n"
415"\n"
416"Deletes the named attribute from the given object.\n"
417"\n"
418"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
419
420#define BUILTIN_DELATTR_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100421 {"delattr", (PyCFunction)builtin_delattr, METH_FASTCALL, builtin_delattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300422
423static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300424builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300425
426static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100427builtin_delattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300428{
429 PyObject *return_value = NULL;
430 PyObject *obj;
431 PyObject *name;
432
Sylvain74453812017-06-10 06:51:48 +0200433 if (!_PyArg_NoStackKeywords("delattr", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200437 if (!_PyArg_UnpackStack(args, nargs, "delattr",
438 2, 2,
439 &obj, &name)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100440 goto exit;
441 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300442 return_value = builtin_delattr_impl(module, obj, name);
443
444exit:
445 return return_value;
446}
447
448PyDoc_STRVAR(builtin_hash__doc__,
449"hash($module, obj, /)\n"
450"--\n"
451"\n"
452"Return the hash value for the given object.\n"
453"\n"
454"Two objects that compare equal must also have the same hash value, but the\n"
455"reverse is not necessarily true.");
456
457#define BUILTIN_HASH_METHODDEF \
458 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
459
460PyDoc_STRVAR(builtin_hex__doc__,
461"hex($module, number, /)\n"
462"--\n"
463"\n"
464"Return the hexadecimal representation of an integer.\n"
465"\n"
466" >>> hex(12648430)\n"
467" \'0xc0ffee\'");
468
469#define BUILTIN_HEX_METHODDEF \
470 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
471
472PyDoc_STRVAR(builtin_len__doc__,
473"len($module, obj, /)\n"
474"--\n"
475"\n"
476"Return the number of items in a container.");
477
478#define BUILTIN_LEN_METHODDEF \
479 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
480
481PyDoc_STRVAR(builtin_locals__doc__,
482"locals($module, /)\n"
483"--\n"
484"\n"
485"Return a dictionary containing the current scope\'s local variables.\n"
486"\n"
487"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
488"the local scope and vice-versa is *implementation dependent* and not\n"
489"covered by any backwards compatibility guarantees.");
490
491#define BUILTIN_LOCALS_METHODDEF \
492 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
493
494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300495builtin_locals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300496
497static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300498builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300499{
500 return builtin_locals_impl(module);
501}
502
503PyDoc_STRVAR(builtin_oct__doc__,
504"oct($module, number, /)\n"
505"--\n"
506"\n"
507"Return the octal representation of an integer.\n"
508"\n"
509" >>> oct(342391)\n"
510" \'0o1234567\'");
511
512#define BUILTIN_OCT_METHODDEF \
513 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
514
515PyDoc_STRVAR(builtin_ord__doc__,
516"ord($module, c, /)\n"
517"--\n"
518"\n"
519"Return the Unicode code point for a one-character string.");
520
521#define BUILTIN_ORD_METHODDEF \
522 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
523
524PyDoc_STRVAR(builtin_pow__doc__,
525"pow($module, x, y, z=None, /)\n"
526"--\n"
527"\n"
528"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
529"\n"
530"Some types, such as ints, are able to use a more efficient algorithm when\n"
531"invoked using the three argument form.");
532
533#define BUILTIN_POW_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100534 {"pow", (PyCFunction)builtin_pow, METH_FASTCALL, builtin_pow__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535
536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300537builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300538
539static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100540builtin_pow(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300541{
542 PyObject *return_value = NULL;
543 PyObject *x;
544 PyObject *y;
545 PyObject *z = Py_None;
546
Sylvain74453812017-06-10 06:51:48 +0200547 if (!_PyArg_NoStackKeywords("pow", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200551 if (!_PyArg_UnpackStack(args, nargs, "pow",
552 2, 3,
553 &x, &y, &z)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100554 goto exit;
555 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300556 return_value = builtin_pow_impl(module, x, y, z);
557
558exit:
559 return return_value;
560}
561
562PyDoc_STRVAR(builtin_input__doc__,
563"input($module, prompt=None, /)\n"
564"--\n"
565"\n"
566"Read a string from standard input. The trailing newline is stripped.\n"
567"\n"
568"The prompt string, if given, is printed to standard output without a\n"
569"trailing newline before reading input.\n"
570"\n"
571"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
572"On *nix systems, readline is used if available.");
573
574#define BUILTIN_INPUT_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100575 {"input", (PyCFunction)builtin_input, METH_FASTCALL, builtin_input__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300576
577static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300578builtin_input_impl(PyObject *module, PyObject *prompt);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300579
580static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100581builtin_input(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300582{
583 PyObject *return_value = NULL;
584 PyObject *prompt = NULL;
585
Sylvain74453812017-06-10 06:51:48 +0200586 if (!_PyArg_NoStackKeywords("input", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200590 if (!_PyArg_UnpackStack(args, nargs, "input",
591 0, 1,
592 &prompt)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100593 goto exit;
594 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300595 return_value = builtin_input_impl(module, prompt);
596
597exit:
598 return return_value;
599}
600
601PyDoc_STRVAR(builtin_repr__doc__,
602"repr($module, obj, /)\n"
603"--\n"
604"\n"
605"Return the canonical string representation of the object.\n"
606"\n"
607"For many object types, including most builtins, eval(repr(obj)) == obj.");
608
609#define BUILTIN_REPR_METHODDEF \
610 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
611
612PyDoc_STRVAR(builtin_sum__doc__,
613"sum($module, iterable, start=0, /)\n"
614"--\n"
615"\n"
616"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
617"\n"
618"When the iterable is empty, return the start value.\n"
619"This function is intended specifically for use with numeric values and may\n"
620"reject non-numeric types.");
621
622#define BUILTIN_SUM_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100623 {"sum", (PyCFunction)builtin_sum, METH_FASTCALL, builtin_sum__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300624
625static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300626builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300627
628static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100629builtin_sum(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300630{
631 PyObject *return_value = NULL;
632 PyObject *iterable;
633 PyObject *start = NULL;
634
Sylvain74453812017-06-10 06:51:48 +0200635 if (!_PyArg_NoStackKeywords("sum", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200639 if (!_PyArg_UnpackStack(args, nargs, "sum",
640 1, 2,
641 &iterable, &start)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100642 goto exit;
643 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300644 return_value = builtin_sum_impl(module, iterable, start);
645
646exit:
647 return return_value;
648}
649
650PyDoc_STRVAR(builtin_isinstance__doc__,
651"isinstance($module, obj, class_or_tuple, /)\n"
652"--\n"
653"\n"
654"Return whether an object is an instance of a class or of a subclass thereof.\n"
655"\n"
656"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
657"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
658"or ...`` etc.");
659
660#define BUILTIN_ISINSTANCE_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100661 {"isinstance", (PyCFunction)builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300662
663static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300664builtin_isinstance_impl(PyObject *module, PyObject *obj,
Larry Hastings89964c42015-04-14 18:07:59 -0400665 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300666
667static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100668builtin_isinstance(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300669{
670 PyObject *return_value = NULL;
671 PyObject *obj;
672 PyObject *class_or_tuple;
673
Sylvain74453812017-06-10 06:51:48 +0200674 if (!_PyArg_NoStackKeywords("isinstance", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200678 if (!_PyArg_UnpackStack(args, nargs, "isinstance",
679 2, 2,
680 &obj, &class_or_tuple)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100681 goto exit;
682 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300683 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
684
685exit:
686 return return_value;
687}
688
689PyDoc_STRVAR(builtin_issubclass__doc__,
690"issubclass($module, cls, class_or_tuple, /)\n"
691"--\n"
692"\n"
693"Return whether \'cls\' is a derived from another class or is the same class.\n"
694"\n"
695"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
696"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
697"or ...`` etc.");
698
699#define BUILTIN_ISSUBCLASS_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100700 {"issubclass", (PyCFunction)builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300701
702static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300703builtin_issubclass_impl(PyObject *module, PyObject *cls,
Larry Hastings89964c42015-04-14 18:07:59 -0400704 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300705
706static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100707builtin_issubclass(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300708{
709 PyObject *return_value = NULL;
710 PyObject *cls;
711 PyObject *class_or_tuple;
712
Sylvain74453812017-06-10 06:51:48 +0200713 if (!_PyArg_NoStackKeywords("issubclass", kwnames)) {
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
Sylvain74453812017-06-10 06:51:48 +0200717 if (!_PyArg_UnpackStack(args, nargs, "issubclass",
718 2, 2,
719 &cls, &class_or_tuple)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100720 goto exit;
721 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300722 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
723
724exit:
725 return return_value;
726}
Sylvain74453812017-06-10 06:51:48 +0200727/*[clinic end generated code: output=e1a7417a7b33eeec input=a9049054013a1b77]*/