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 \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 85 | {"format", (PyCFunction)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 * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 91 | builtin_format(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
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_NoStackKeywords("format", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 98 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 99 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 100 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 101 | if (!_PyArg_ParseStack(args, nargs, "O|U:format", |
| 102 | &value, &format_spec)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 103 | goto exit; |
| 104 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 105 | return_value = builtin_format_impl(module, value, format_spec); |
| 106 | |
| 107 | exit: |
| 108 | return return_value; |
| 109 | } |
| 110 | |
| 111 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 118 | {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 119 | |
| 120 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 121 | builtin_chr_impl(PyObject *module, int i); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 122 | |
| 123 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 124 | builtin_chr(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 125 | { |
| 126 | PyObject *return_value = NULL; |
| 127 | int i; |
| 128 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 129 | if (!PyArg_Parse(arg, "i:chr", &i)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 130 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 131 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 132 | return_value = builtin_chr_impl(module, i); |
| 133 | |
| 134 | exit: |
| 135 | return return_value; |
| 136 | } |
| 137 | |
| 138 | PyDoc_STRVAR(builtin_compile__doc__, |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 139 | "compile($module, /, source, filename, mode, flags=0,\n" |
| 140 | " dont_inherit=False, optimize=-1)\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 141 | "--\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 Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 151 | "The dont_inherit argument, if true, stops the compilation inheriting\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 152 | "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] | 153 | "compile; if absent or false these statements do influence the compilation,\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 154 | "in addition to any features explicitly specified."); |
| 155 | |
| 156 | #define BUILTIN_COMPILE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 157 | {"compile", (PyCFunction)builtin_compile, METH_FASTCALL, builtin_compile__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 158 | |
| 159 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 160 | builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, |
| 161 | const char *mode, int flags, int dont_inherit, |
| 162 | int optimize); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 163 | |
| 164 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 165 | builtin_compile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 166 | { |
| 167 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 168 | 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 Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 170 | PyObject *source; |
| 171 | PyObject *filename; |
| 172 | const char *mode; |
| 173 | int flags = 0; |
| 174 | int dont_inherit = 0; |
| 175 | int optimize = -1; |
| 176 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 177 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 178 | &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 179 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 180 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 181 | return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize); |
| 182 | |
| 183 | exit: |
| 184 | return return_value; |
| 185 | } |
| 186 | |
| 187 | PyDoc_STRVAR(builtin_divmod__doc__, |
| 188 | "divmod($module, x, y, /)\n" |
| 189 | "--\n" |
| 190 | "\n" |
Serhiy Storchaka | df07173 | 2016-05-01 20:33:24 +0300 | [diff] [blame] | 191 | "Return the tuple (x//y, x%y). Invariant: div*y + mod == x."); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 192 | |
| 193 | #define BUILTIN_DIVMOD_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 194 | {"divmod", (PyCFunction)builtin_divmod, METH_FASTCALL, builtin_divmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 195 | |
| 196 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 197 | builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 198 | |
| 199 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 200 | builtin_divmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 201 | { |
| 202 | PyObject *return_value = NULL; |
| 203 | PyObject *x; |
| 204 | PyObject *y; |
| 205 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 206 | if (!_PyArg_NoStackKeywords("divmod", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 207 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 208 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 209 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 210 | if (!_PyArg_UnpackStack(args, nargs, "divmod", |
| 211 | 2, 2, |
| 212 | &x, &y)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 213 | goto exit; |
| 214 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 215 | return_value = builtin_divmod_impl(module, x, y); |
| 216 | |
| 217 | exit: |
| 218 | return return_value; |
| 219 | } |
| 220 | |
| 221 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 234 | {"eval", (PyCFunction)builtin_eval, METH_FASTCALL, builtin_eval__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 235 | |
| 236 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 237 | builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 238 | PyObject *locals); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 239 | |
| 240 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 241 | builtin_eval(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 242 | { |
| 243 | PyObject *return_value = NULL; |
| 244 | PyObject *source; |
| 245 | PyObject *globals = Py_None; |
| 246 | PyObject *locals = Py_None; |
| 247 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 248 | if (!_PyArg_NoStackKeywords("eval", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 249 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 250 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 251 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 252 | if (!_PyArg_UnpackStack(args, nargs, "eval", |
| 253 | 1, 3, |
| 254 | &source, &globals, &locals)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 255 | goto exit; |
| 256 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 257 | return_value = builtin_eval_impl(module, source, globals, locals); |
| 258 | |
| 259 | exit: |
| 260 | return return_value; |
| 261 | } |
| 262 | |
| 263 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 276 | {"exec", (PyCFunction)builtin_exec, METH_FASTCALL, builtin_exec__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 277 | |
| 278 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 279 | builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 280 | PyObject *locals); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 281 | |
| 282 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 283 | builtin_exec(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 284 | { |
| 285 | PyObject *return_value = NULL; |
| 286 | PyObject *source; |
| 287 | PyObject *globals = Py_None; |
| 288 | PyObject *locals = Py_None; |
| 289 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 290 | if (!_PyArg_NoStackKeywords("exec", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 291 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 292 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 293 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 294 | if (!_PyArg_UnpackStack(args, nargs, "exec", |
| 295 | 1, 3, |
| 296 | &source, &globals, &locals)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 297 | goto exit; |
| 298 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 299 | return_value = builtin_exec_impl(module, source, globals, locals); |
| 300 | |
| 301 | exit: |
| 302 | return return_value; |
| 303 | } |
| 304 | |
| 305 | PyDoc_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 | |
| 317 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 318 | builtin_globals_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 319 | |
| 320 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 321 | builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 322 | { |
| 323 | return builtin_globals_impl(module); |
| 324 | } |
| 325 | |
| 326 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 335 | {"hasattr", (PyCFunction)builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 336 | |
| 337 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 338 | builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 339 | |
| 340 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 341 | builtin_hasattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 342 | { |
| 343 | PyObject *return_value = NULL; |
| 344 | PyObject *obj; |
| 345 | PyObject *name; |
| 346 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 347 | if (!_PyArg_NoStackKeywords("hasattr", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 348 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 349 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 350 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 351 | if (!_PyArg_UnpackStack(args, nargs, "hasattr", |
| 352 | 2, 2, |
| 353 | &obj, &name)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 354 | goto exit; |
| 355 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 356 | return_value = builtin_hasattr_impl(module, obj, name); |
| 357 | |
| 358 | exit: |
| 359 | return return_value; |
| 360 | } |
| 361 | |
| 362 | PyDoc_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 | |
| 374 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 383 | {"setattr", (PyCFunction)builtin_setattr, METH_FASTCALL, builtin_setattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 384 | |
| 385 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 386 | builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 387 | PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 388 | |
| 389 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 390 | builtin_setattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 391 | { |
| 392 | PyObject *return_value = NULL; |
| 393 | PyObject *obj; |
| 394 | PyObject *name; |
| 395 | PyObject *value; |
| 396 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 397 | if (!_PyArg_NoStackKeywords("setattr", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 398 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 399 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 400 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 401 | if (!_PyArg_UnpackStack(args, nargs, "setattr", |
| 402 | 3, 3, |
| 403 | &obj, &name, &value)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 404 | goto exit; |
| 405 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 406 | return_value = builtin_setattr_impl(module, obj, name, value); |
| 407 | |
| 408 | exit: |
| 409 | return return_value; |
| 410 | } |
| 411 | |
| 412 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 421 | {"delattr", (PyCFunction)builtin_delattr, METH_FASTCALL, builtin_delattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 422 | |
| 423 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 424 | builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 425 | |
| 426 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 427 | builtin_delattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 428 | { |
| 429 | PyObject *return_value = NULL; |
| 430 | PyObject *obj; |
| 431 | PyObject *name; |
| 432 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 433 | if (!_PyArg_NoStackKeywords("delattr", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 434 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 435 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 436 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 437 | if (!_PyArg_UnpackStack(args, nargs, "delattr", |
| 438 | 2, 2, |
| 439 | &obj, &name)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 440 | goto exit; |
| 441 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 442 | return_value = builtin_delattr_impl(module, obj, name); |
| 443 | |
| 444 | exit: |
| 445 | return return_value; |
| 446 | } |
| 447 | |
| 448 | PyDoc_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 | |
| 460 | PyDoc_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 | |
| 472 | PyDoc_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 | |
| 481 | PyDoc_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 | |
| 494 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 495 | builtin_locals_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 496 | |
| 497 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 498 | builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 499 | { |
| 500 | return builtin_locals_impl(module); |
| 501 | } |
| 502 | |
| 503 | PyDoc_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 | |
| 515 | PyDoc_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 | |
| 524 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 534 | {"pow", (PyCFunction)builtin_pow, METH_FASTCALL, builtin_pow__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 535 | |
| 536 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 537 | builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 538 | |
| 539 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 540 | builtin_pow(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 541 | { |
| 542 | PyObject *return_value = NULL; |
| 543 | PyObject *x; |
| 544 | PyObject *y; |
| 545 | PyObject *z = Py_None; |
| 546 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 547 | if (!_PyArg_NoStackKeywords("pow", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 548 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 549 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 550 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 551 | if (!_PyArg_UnpackStack(args, nargs, "pow", |
| 552 | 2, 3, |
| 553 | &x, &y, &z)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 554 | goto exit; |
| 555 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 556 | return_value = builtin_pow_impl(module, x, y, z); |
| 557 | |
| 558 | exit: |
| 559 | return return_value; |
| 560 | } |
| 561 | |
| 562 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 575 | {"input", (PyCFunction)builtin_input, METH_FASTCALL, builtin_input__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 576 | |
| 577 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 578 | builtin_input_impl(PyObject *module, PyObject *prompt); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 579 | |
| 580 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 581 | builtin_input(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 582 | { |
| 583 | PyObject *return_value = NULL; |
| 584 | PyObject *prompt = NULL; |
| 585 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 586 | if (!_PyArg_NoStackKeywords("input", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 587 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 588 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 589 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 590 | if (!_PyArg_UnpackStack(args, nargs, "input", |
| 591 | 0, 1, |
| 592 | &prompt)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 593 | goto exit; |
| 594 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 595 | return_value = builtin_input_impl(module, prompt); |
| 596 | |
| 597 | exit: |
| 598 | return return_value; |
| 599 | } |
| 600 | |
| 601 | PyDoc_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 | |
| 612 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 623 | {"sum", (PyCFunction)builtin_sum, METH_FASTCALL, builtin_sum__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 624 | |
| 625 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 626 | builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 627 | |
| 628 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 629 | builtin_sum(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 630 | { |
| 631 | PyObject *return_value = NULL; |
| 632 | PyObject *iterable; |
| 633 | PyObject *start = NULL; |
| 634 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 635 | if (!_PyArg_NoStackKeywords("sum", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 636 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 637 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 638 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 639 | if (!_PyArg_UnpackStack(args, nargs, "sum", |
| 640 | 1, 2, |
| 641 | &iterable, &start)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 642 | goto exit; |
| 643 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 644 | return_value = builtin_sum_impl(module, iterable, start); |
| 645 | |
| 646 | exit: |
| 647 | return return_value; |
| 648 | } |
| 649 | |
| 650 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 661 | {"isinstance", (PyCFunction)builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 662 | |
| 663 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 664 | builtin_isinstance_impl(PyObject *module, PyObject *obj, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 665 | PyObject *class_or_tuple); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 666 | |
| 667 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 668 | builtin_isinstance(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 669 | { |
| 670 | PyObject *return_value = NULL; |
| 671 | PyObject *obj; |
| 672 | PyObject *class_or_tuple; |
| 673 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 674 | if (!_PyArg_NoStackKeywords("isinstance", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 675 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 676 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 677 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 678 | if (!_PyArg_UnpackStack(args, nargs, "isinstance", |
| 679 | 2, 2, |
| 680 | &obj, &class_or_tuple)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 681 | goto exit; |
| 682 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 683 | return_value = builtin_isinstance_impl(module, obj, class_or_tuple); |
| 684 | |
| 685 | exit: |
| 686 | return return_value; |
| 687 | } |
| 688 | |
| 689 | PyDoc_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 Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 700 | {"issubclass", (PyCFunction)builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 701 | |
| 702 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 703 | builtin_issubclass_impl(PyObject *module, PyObject *cls, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 704 | PyObject *class_or_tuple); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 705 | |
| 706 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 707 | builtin_issubclass(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 708 | { |
| 709 | PyObject *return_value = NULL; |
| 710 | PyObject *cls; |
| 711 | PyObject *class_or_tuple; |
| 712 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 713 | if (!_PyArg_NoStackKeywords("issubclass", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 714 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 715 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 716 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 717 | if (!_PyArg_UnpackStack(args, nargs, "issubclass", |
| 718 | 2, 2, |
| 719 | &cls, &class_or_tuple)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 720 | goto exit; |
| 721 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 722 | return_value = builtin_issubclass_impl(module, cls, class_or_tuple); |
| 723 | |
| 724 | exit: |
| 725 | return return_value; |
| 726 | } |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 727 | /*[clinic end generated code: output=e1a7417a7b33eeec input=a9049054013a1b77]*/ |