blob: df9970942b742371a519a344ba296eb6ba02735e [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 \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020085 {"format", (PyCFunction)(void(*)(void))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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020091builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030092{
93 PyObject *return_value = NULL;
94 PyObject *value;
95 PyObject *format_spec = NULL;
96
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020097 if (!_PyArg_CheckPositional("format", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010098 goto exit;
99 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200100 value = args[0];
101 if (nargs < 2) {
102 goto skip_optional;
103 }
104 if (!PyUnicode_Check(args[1])) {
105 _PyArg_BadArgument("format", 2, "str", args[1]);
106 goto exit;
107 }
108 if (PyUnicode_READY(args[1]) == -1) {
109 goto exit;
110 }
111 format_spec = args[1];
112skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300113 return_value = builtin_format_impl(module, value, format_spec);
114
115exit:
116 return return_value;
117}
118
119PyDoc_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 \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300126 {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300127
128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300129builtin_chr_impl(PyObject *module, int i);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130
131static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300132builtin_chr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300133{
134 PyObject *return_value = NULL;
135 int i;
136
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200137 if (PyFloat_Check(arg)) {
138 PyErr_SetString(PyExc_TypeError,
139 "integer argument expected, got float" );
140 goto exit;
141 }
142 i = _PyLong_AsInt(arg);
143 if (i == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300144 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300145 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300146 return_value = builtin_chr_impl(module, i);
147
148exit:
149 return return_value;
150}
151
152PyDoc_STRVAR(builtin_compile__doc__,
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300153"compile($module, /, source, filename, mode, flags=0,\n"
Guido van Rossum495da292019-03-07 12:38:08 -0800154" dont_inherit=False, optimize=-1, feature_version=-1)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300155"--\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"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300165"The dont_inherit argument, if true, stops the compilation inheriting\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300166"the effects of any future statements in effect in the code calling\n"
Serhiy Storchaka8b2e8b62015-05-30 11:30:39 +0300167"compile; if absent or false these statements do influence the compilation,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300168"in addition to any features explicitly specified.");
169
170#define BUILTIN_COMPILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200171 {"compile", (PyCFunction)(void(*)(void))builtin_compile, METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300172
173static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300174builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
175 const char *mode, int flags, int dont_inherit,
Guido van Rossum495da292019-03-07 12:38:08 -0800176 int optimize, int feature_version);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300177
178static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200179builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300180{
181 PyObject *return_value = NULL;
Guido van Rossum495da292019-03-07 12:38:08 -0800182 static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "feature_version", NULL};
183 static _PyArg_Parser _parser = {"OO&s|iiii:compile", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300184 PyObject *source;
185 PyObject *filename;
186 const char *mode;
187 int flags = 0;
188 int dont_inherit = 0;
189 int optimize = -1;
Guido van Rossum495da292019-03-07 12:38:08 -0800190 int feature_version = -1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300191
Victor Stinner3e1fad62017-01-17 01:29:01 +0100192 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Guido van Rossum495da292019-03-07 12:38:08 -0800193 &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize, &feature_version)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300195 }
Guido van Rossum495da292019-03-07 12:38:08 -0800196 return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300197
198exit:
199 return return_value;
200}
201
202PyDoc_STRVAR(builtin_divmod__doc__,
203"divmod($module, x, y, /)\n"
204"--\n"
205"\n"
Serhiy Storchakadf071732016-05-01 20:33:24 +0300206"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300207
208#define BUILTIN_DIVMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200209 {"divmod", (PyCFunction)(void(*)(void))builtin_divmod, METH_FASTCALL, builtin_divmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300210
211static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300212builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300213
214static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200215builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300216{
217 PyObject *return_value = NULL;
218 PyObject *x;
219 PyObject *y;
220
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200221 if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100222 goto exit;
223 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200224 x = args[0];
225 y = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300226 return_value = builtin_divmod_impl(module, x, y);
227
228exit:
229 return return_value;
230}
231
232PyDoc_STRVAR(builtin_eval__doc__,
233"eval($module, source, globals=None, locals=None, /)\n"
234"--\n"
235"\n"
236"Evaluate the given source in the context of globals and locals.\n"
237"\n"
238"The source may be a string representing a Python expression\n"
239"or a code object as returned by compile().\n"
240"The globals must be a dictionary and locals can be any mapping,\n"
241"defaulting to the current globals and locals.\n"
242"If only globals is given, locals defaults to it.");
243
244#define BUILTIN_EVAL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200245 {"eval", (PyCFunction)(void(*)(void))builtin_eval, METH_FASTCALL, builtin_eval__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300246
247static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300248builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400249 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300250
251static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200252builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300253{
254 PyObject *return_value = NULL;
255 PyObject *source;
256 PyObject *globals = Py_None;
257 PyObject *locals = Py_None;
258
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200259 if (!_PyArg_CheckPositional("eval", nargs, 1, 3)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100260 goto exit;
261 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200262 source = args[0];
263 if (nargs < 2) {
264 goto skip_optional;
265 }
266 globals = args[1];
267 if (nargs < 3) {
268 goto skip_optional;
269 }
270 locals = args[2];
271skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300272 return_value = builtin_eval_impl(module, source, globals, locals);
273
274exit:
275 return return_value;
276}
277
278PyDoc_STRVAR(builtin_exec__doc__,
279"exec($module, source, globals=None, locals=None, /)\n"
280"--\n"
281"\n"
282"Execute the given source in the context of globals and locals.\n"
283"\n"
284"The source may be a string representing one or more Python statements\n"
285"or a code object as returned by compile().\n"
286"The globals must be a dictionary and locals can be any mapping,\n"
287"defaulting to the current globals and locals.\n"
288"If only globals is given, locals defaults to it.");
289
290#define BUILTIN_EXEC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200291 {"exec", (PyCFunction)(void(*)(void))builtin_exec, METH_FASTCALL, builtin_exec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300292
293static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300294builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Larry Hastings89964c42015-04-14 18:07:59 -0400295 PyObject *locals);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300296
297static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200298builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300299{
300 PyObject *return_value = NULL;
301 PyObject *source;
302 PyObject *globals = Py_None;
303 PyObject *locals = Py_None;
304
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200305 if (!_PyArg_CheckPositional("exec", nargs, 1, 3)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100306 goto exit;
307 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200308 source = args[0];
309 if (nargs < 2) {
310 goto skip_optional;
311 }
312 globals = args[1];
313 if (nargs < 3) {
314 goto skip_optional;
315 }
316 locals = args[2];
317skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300318 return_value = builtin_exec_impl(module, source, globals, locals);
319
320exit:
321 return return_value;
322}
323
324PyDoc_STRVAR(builtin_globals__doc__,
325"globals($module, /)\n"
326"--\n"
327"\n"
328"Return the dictionary containing the current scope\'s global variables.\n"
329"\n"
330"NOTE: Updates to this dictionary *will* affect name lookups in the current\n"
331"global scope and vice-versa.");
332
333#define BUILTIN_GLOBALS_METHODDEF \
334 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__},
335
336static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300337builtin_globals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300338
339static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300340builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300341{
342 return builtin_globals_impl(module);
343}
344
345PyDoc_STRVAR(builtin_hasattr__doc__,
346"hasattr($module, obj, name, /)\n"
347"--\n"
348"\n"
349"Return whether the object has an attribute with the given name.\n"
350"\n"
351"This is done by calling getattr(obj, name) and catching AttributeError.");
352
353#define BUILTIN_HASATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200354 {"hasattr", (PyCFunction)(void(*)(void))builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300355
356static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300357builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300358
359static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200360builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300361{
362 PyObject *return_value = NULL;
363 PyObject *obj;
364 PyObject *name;
365
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200366 if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100367 goto exit;
368 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200369 obj = args[0];
370 name = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300371 return_value = builtin_hasattr_impl(module, obj, name);
372
373exit:
374 return return_value;
375}
376
377PyDoc_STRVAR(builtin_id__doc__,
378"id($module, obj, /)\n"
379"--\n"
380"\n"
381"Return the identity of an object.\n"
382"\n"
383"This is guaranteed to be unique among simultaneously existing objects.\n"
384"(CPython uses the object\'s memory address.)");
385
386#define BUILTIN_ID_METHODDEF \
387 {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
388
389PyDoc_STRVAR(builtin_setattr__doc__,
390"setattr($module, obj, name, value, /)\n"
391"--\n"
392"\n"
393"Sets the named attribute on the given object to the specified value.\n"
394"\n"
395"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
396
397#define BUILTIN_SETATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200398 {"setattr", (PyCFunction)(void(*)(void))builtin_setattr, METH_FASTCALL, builtin_setattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300399
400static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300401builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
Larry Hastings89964c42015-04-14 18:07:59 -0400402 PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300403
404static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200405builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300406{
407 PyObject *return_value = NULL;
408 PyObject *obj;
409 PyObject *name;
410 PyObject *value;
411
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200412 if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100413 goto exit;
414 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200415 obj = args[0];
416 name = args[1];
417 value = args[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300418 return_value = builtin_setattr_impl(module, obj, name, value);
419
420exit:
421 return return_value;
422}
423
424PyDoc_STRVAR(builtin_delattr__doc__,
425"delattr($module, obj, name, /)\n"
426"--\n"
427"\n"
428"Deletes the named attribute from the given object.\n"
429"\n"
430"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
431
432#define BUILTIN_DELATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200433 {"delattr", (PyCFunction)(void(*)(void))builtin_delattr, METH_FASTCALL, builtin_delattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300434
435static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300436builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300437
438static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200439builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300440{
441 PyObject *return_value = NULL;
442 PyObject *obj;
443 PyObject *name;
444
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200445 if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100446 goto exit;
447 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200448 obj = args[0];
449 name = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300450 return_value = builtin_delattr_impl(module, obj, name);
451
452exit:
453 return return_value;
454}
455
456PyDoc_STRVAR(builtin_hash__doc__,
457"hash($module, obj, /)\n"
458"--\n"
459"\n"
460"Return the hash value for the given object.\n"
461"\n"
462"Two objects that compare equal must also have the same hash value, but the\n"
463"reverse is not necessarily true.");
464
465#define BUILTIN_HASH_METHODDEF \
466 {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
467
468PyDoc_STRVAR(builtin_hex__doc__,
469"hex($module, number, /)\n"
470"--\n"
471"\n"
472"Return the hexadecimal representation of an integer.\n"
473"\n"
474" >>> hex(12648430)\n"
475" \'0xc0ffee\'");
476
477#define BUILTIN_HEX_METHODDEF \
478 {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
479
480PyDoc_STRVAR(builtin_len__doc__,
481"len($module, obj, /)\n"
482"--\n"
483"\n"
484"Return the number of items in a container.");
485
486#define BUILTIN_LEN_METHODDEF \
487 {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__},
488
489PyDoc_STRVAR(builtin_locals__doc__,
490"locals($module, /)\n"
491"--\n"
492"\n"
493"Return a dictionary containing the current scope\'s local variables.\n"
494"\n"
495"NOTE: Whether or not updates to this dictionary will affect name lookups in\n"
496"the local scope and vice-versa is *implementation dependent* and not\n"
497"covered by any backwards compatibility guarantees.");
498
499#define BUILTIN_LOCALS_METHODDEF \
500 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__},
501
502static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300503builtin_locals_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504
505static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300506builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300507{
508 return builtin_locals_impl(module);
509}
510
511PyDoc_STRVAR(builtin_oct__doc__,
512"oct($module, number, /)\n"
513"--\n"
514"\n"
515"Return the octal representation of an integer.\n"
516"\n"
517" >>> oct(342391)\n"
518" \'0o1234567\'");
519
520#define BUILTIN_OCT_METHODDEF \
521 {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
522
523PyDoc_STRVAR(builtin_ord__doc__,
524"ord($module, c, /)\n"
525"--\n"
526"\n"
527"Return the Unicode code point for a one-character string.");
528
529#define BUILTIN_ORD_METHODDEF \
530 {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
531
532PyDoc_STRVAR(builtin_pow__doc__,
533"pow($module, x, y, z=None, /)\n"
534"--\n"
535"\n"
536"Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n"
537"\n"
538"Some types, such as ints, are able to use a more efficient algorithm when\n"
539"invoked using the three argument form.");
540
541#define BUILTIN_POW_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200542 {"pow", (PyCFunction)(void(*)(void))builtin_pow, METH_FASTCALL, builtin_pow__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300543
544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300545builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300546
547static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200548builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300549{
550 PyObject *return_value = NULL;
551 PyObject *x;
552 PyObject *y;
553 PyObject *z = Py_None;
554
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200555 if (!_PyArg_CheckPositional("pow", nargs, 2, 3)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100556 goto exit;
557 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200558 x = args[0];
559 y = args[1];
560 if (nargs < 3) {
561 goto skip_optional;
562 }
563 z = args[2];
564skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300565 return_value = builtin_pow_impl(module, x, y, z);
566
567exit:
568 return return_value;
569}
570
571PyDoc_STRVAR(builtin_input__doc__,
572"input($module, prompt=None, /)\n"
573"--\n"
574"\n"
575"Read a string from standard input. The trailing newline is stripped.\n"
576"\n"
577"The prompt string, if given, is printed to standard output without a\n"
578"trailing newline before reading input.\n"
579"\n"
580"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n"
581"On *nix systems, readline is used if available.");
582
583#define BUILTIN_INPUT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200584 {"input", (PyCFunction)(void(*)(void))builtin_input, METH_FASTCALL, builtin_input__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300585
586static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300587builtin_input_impl(PyObject *module, PyObject *prompt);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300588
589static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200590builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300591{
592 PyObject *return_value = NULL;
593 PyObject *prompt = NULL;
594
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200595 if (!_PyArg_CheckPositional("input", nargs, 0, 1)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100596 goto exit;
597 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200598 if (nargs < 1) {
599 goto skip_optional;
600 }
601 prompt = args[0];
602skip_optional:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300603 return_value = builtin_input_impl(module, prompt);
604
605exit:
606 return return_value;
607}
608
609PyDoc_STRVAR(builtin_repr__doc__,
610"repr($module, obj, /)\n"
611"--\n"
612"\n"
613"Return the canonical string representation of the object.\n"
614"\n"
615"For many object types, including most builtins, eval(repr(obj)) == obj.");
616
617#define BUILTIN_REPR_METHODDEF \
618 {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__},
619
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200620PyDoc_STRVAR(builtin_round__doc__,
621"round($module, /, number, ndigits=None)\n"
622"--\n"
623"\n"
624"Round a number to a given precision in decimal digits.\n"
625"\n"
626"The return value is an integer if ndigits is omitted or None. Otherwise\n"
627"the return value has the same type as the number. ndigits may be negative.");
628
629#define BUILTIN_ROUND_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200630 {"round", (PyCFunction)(void(*)(void))builtin_round, METH_FASTCALL|METH_KEYWORDS, builtin_round__doc__},
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200631
632static PyObject *
633builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits);
634
635static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200636builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaaca7f572017-11-15 17:51:14 +0200637{
638 PyObject *return_value = NULL;
639 static const char * const _keywords[] = {"number", "ndigits", NULL};
640 static _PyArg_Parser _parser = {"O|O:round", _keywords, 0};
641 PyObject *number;
642 PyObject *ndigits = NULL;
643
644 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
645 &number, &ndigits)) {
646 goto exit;
647 }
648 return_value = builtin_round_impl(module, number, ndigits);
649
650exit:
651 return return_value;
652}
653
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300654PyDoc_STRVAR(builtin_sum__doc__,
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700655"sum($module, iterable, /, start=0)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300656"--\n"
657"\n"
658"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n"
659"\n"
660"When the iterable is empty, return the start value.\n"
661"This function is intended specifically for use with numeric values and may\n"
662"reject non-numeric types.");
663
664#define BUILTIN_SUM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200665 {"sum", (PyCFunction)(void(*)(void))builtin_sum, METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300666
667static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300668builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300669
670static PyObject *
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700671builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300672{
673 PyObject *return_value = NULL;
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700674 static const char * const _keywords[] = {"", "start", NULL};
675 static _PyArg_Parser _parser = {"O|O:sum", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300676 PyObject *iterable;
677 PyObject *start = NULL;
678
Raymond Hettinger9dfa0fe2018-09-12 10:54:06 -0700679 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Sylvain74453812017-06-10 06:51:48 +0200680 &iterable, &start)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100681 goto exit;
682 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300683 return_value = builtin_sum_impl(module, iterable, start);
684
685exit:
686 return return_value;
687}
688
689PyDoc_STRVAR(builtin_isinstance__doc__,
690"isinstance($module, obj, class_or_tuple, /)\n"
691"--\n"
692"\n"
693"Return whether an object is an instance of a class or of a subclass thereof.\n"
694"\n"
695"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n"
696"check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n"
697"or ...`` etc.");
698
699#define BUILTIN_ISINSTANCE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200700 {"isinstance", (PyCFunction)(void(*)(void))builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300701
702static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300703builtin_isinstance_impl(PyObject *module, PyObject *obj,
Larry Hastings89964c42015-04-14 18:07:59 -0400704 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300705
706static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200707builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300708{
709 PyObject *return_value = NULL;
710 PyObject *obj;
711 PyObject *class_or_tuple;
712
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200713 if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100714 goto exit;
715 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200716 obj = args[0];
717 class_or_tuple = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300718 return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
719
720exit:
721 return return_value;
722}
723
724PyDoc_STRVAR(builtin_issubclass__doc__,
725"issubclass($module, cls, class_or_tuple, /)\n"
726"--\n"
727"\n"
728"Return whether \'cls\' is a derived from another class or is the same class.\n"
729"\n"
730"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n"
731"check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n"
732"or ...`` etc.");
733
734#define BUILTIN_ISSUBCLASS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200735 {"issubclass", (PyCFunction)(void(*)(void))builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300736
737static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300738builtin_issubclass_impl(PyObject *module, PyObject *cls,
Larry Hastings89964c42015-04-14 18:07:59 -0400739 PyObject *class_or_tuple);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300740
741static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200742builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300743{
744 PyObject *return_value = NULL;
745 PyObject *cls;
746 PyObject *class_or_tuple;
747
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200748 if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100749 goto exit;
750 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200751 cls = args[0];
752 class_or_tuple = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300753 return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
754
755exit:
756 return return_value;
757}
Guido van Rossum495da292019-03-07 12:38:08 -0800758/*[clinic end generated code: output=00b97a48ea49eaf2 input=a9049054013a1b77]*/