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