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