summaryrefslogtreecommitdiffstats
path: root/Python/clinic
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2022-12-24 14:45:47 (GMT)
committerGitHub <noreply@github.com>2022-12-24 14:45:47 (GMT)
commitbdfb6943861431a79e63f0da2e6b3fe163c12bc7 (patch)
tree18ea678c9448cfe0fa193ccaf594b87abab98606 /Python/clinic
parent0769f957514300a75be51fc6d1b963c8e359208b (diff)
downloadcpython-bdfb6943861431a79e63f0da2e6b3fe163c12bc7.zip
cpython-bdfb6943861431a79e63f0da2e6b3fe163c12bc7.tar.gz
cpython-bdfb6943861431a79e63f0da2e6b3fe163c12bc7.tar.bz2
gh-100357: Convert several functions in `bltinsmodule` to AC (#100358)
Diffstat (limited to 'Python/clinic')
-rw-r--r--Python/clinic/bltinmodule.c.h196
1 files changed, 195 insertions, 1 deletions
diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h
index 89f069d..baf9555 100644
--- a/Python/clinic/bltinmodule.c.h
+++ b/Python/clinic/bltinmodule.c.h
@@ -386,6 +386,49 @@ exit:
return return_value;
}
+PyDoc_STRVAR(builtin_dir__doc__,
+"dir($module, arg=<unrepresentable>, /)\n"
+"--\n"
+"\n"
+"Show attributes of an object.\n"
+"\n"
+"If called without an argument, return the names in the current scope.\n"
+"Else, return an alphabetized list of names comprising (some of) the attributes\n"
+"of the given object, and of attributes reachable from it.\n"
+"If the object supplies a method named __dir__, it will be used; otherwise\n"
+"the default dir() logic is used and returns:\n"
+" for a module object: the module\'s attributes.\n"
+" for a class object: its attributes, and recursively the attributes\n"
+" of its bases.\n"
+" for any other object: its attributes, its class\'s attributes, and\n"
+" recursively the attributes of its class\'s base classes.");
+
+#define BUILTIN_DIR_METHODDEF \
+ {"dir", _PyCFunction_CAST(builtin_dir), METH_FASTCALL, builtin_dir__doc__},
+
+static PyObject *
+builtin_dir_impl(PyObject *module, PyObject *arg);
+
+static PyObject *
+builtin_dir(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *arg = NULL;
+
+ if (!_PyArg_CheckPositional("dir", nargs, 0, 1)) {
+ goto exit;
+ }
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ arg = args[0];
+skip_optional:
+ return_value = builtin_dir_impl(module, arg);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(builtin_divmod__doc__,
"divmod($module, x, y, /)\n"
"--\n"
@@ -546,6 +589,47 @@ exit:
return return_value;
}
+PyDoc_STRVAR(builtin_getattr__doc__,
+"getattr($module, object, name, default=<unrepresentable>, /)\n"
+"--\n"
+"\n"
+"Get a named attribute from an object.\n"
+"\n"
+"getattr(x, \'y\') is equivalent to x.y\n"
+"When a default argument is given, it is returned when the attribute doesn\'t\n"
+"exist; without it, an exception is raised in that case.");
+
+#define BUILTIN_GETATTR_METHODDEF \
+ {"getattr", _PyCFunction_CAST(builtin_getattr), METH_FASTCALL, builtin_getattr__doc__},
+
+static PyObject *
+builtin_getattr_impl(PyObject *module, PyObject *object, PyObject *name,
+ PyObject *default_value);
+
+static PyObject *
+builtin_getattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *object;
+ PyObject *name;
+ PyObject *default_value = NULL;
+
+ if (!_PyArg_CheckPositional("getattr", nargs, 2, 3)) {
+ goto exit;
+ }
+ object = args[0];
+ name = args[1];
+ if (nargs < 3) {
+ goto skip_optional;
+ }
+ default_value = args[2];
+skip_optional:
+ return_value = builtin_getattr_impl(module, object, name, default_value);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(builtin_globals__doc__,
"globals($module, /)\n"
"--\n"
@@ -611,6 +695,44 @@ PyDoc_STRVAR(builtin_id__doc__,
#define BUILTIN_ID_METHODDEF \
{"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__},
+PyDoc_STRVAR(builtin_next__doc__,
+"next($module, iterator, default=<unrepresentable>, /)\n"
+"--\n"
+"\n"
+"Return the next item from the iterator.\n"
+"\n"
+"If default is given and the iterator is exhausted,\n"
+"it is returned instead of raising StopIteration.");
+
+#define BUILTIN_NEXT_METHODDEF \
+ {"next", _PyCFunction_CAST(builtin_next), METH_FASTCALL, builtin_next__doc__},
+
+static PyObject *
+builtin_next_impl(PyObject *module, PyObject *iterator,
+ PyObject *default_value);
+
+static PyObject *
+builtin_next(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *iterator;
+ PyObject *default_value = NULL;
+
+ if (!_PyArg_CheckPositional("next", nargs, 1, 2)) {
+ goto exit;
+ }
+ iterator = args[0];
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ default_value = args[1];
+skip_optional:
+ return_value = builtin_next_impl(module, iterator, default_value);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(builtin_setattr__doc__,
"setattr($module, obj, name, value, /)\n"
"--\n"
@@ -702,6 +824,43 @@ PyDoc_STRVAR(builtin_hex__doc__,
#define BUILTIN_HEX_METHODDEF \
{"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
+PyDoc_STRVAR(builtin_iter__doc__,
+"iter($module, object, sentinel=<unrepresentable>, /)\n"
+"--\n"
+"\n"
+"Get an iterator from an object.\n"
+"\n"
+"In the first form, the argument must supply its own iterator, or be a sequence.\n"
+"In the second form, the callable is called until it returns the sentinel.");
+
+#define BUILTIN_ITER_METHODDEF \
+ {"iter", _PyCFunction_CAST(builtin_iter), METH_FASTCALL, builtin_iter__doc__},
+
+static PyObject *
+builtin_iter_impl(PyObject *module, PyObject *object, PyObject *sentinel);
+
+static PyObject *
+builtin_iter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *object;
+ PyObject *sentinel = NULL;
+
+ if (!_PyArg_CheckPositional("iter", nargs, 1, 2)) {
+ goto exit;
+ }
+ object = args[0];
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ sentinel = args[1];
+skip_optional:
+ return_value = builtin_iter_impl(module, object, sentinel);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(builtin_aiter__doc__,
"aiter($module, async_iterable, /)\n"
"--\n"
@@ -1080,6 +1239,41 @@ exit:
return return_value;
}
+PyDoc_STRVAR(builtin_vars__doc__,
+"vars($module, object=<unrepresentable>, /)\n"
+"--\n"
+"\n"
+"Show vars.\n"
+"\n"
+"Without arguments, equivalent to locals().\n"
+"With an argument, equivalent to object.__dict__.");
+
+#define BUILTIN_VARS_METHODDEF \
+ {"vars", _PyCFunction_CAST(builtin_vars), METH_FASTCALL, builtin_vars__doc__},
+
+static PyObject *
+builtin_vars_impl(PyObject *module, PyObject *object);
+
+static PyObject *
+builtin_vars(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *object = NULL;
+
+ if (!_PyArg_CheckPositional("vars", nargs, 0, 1)) {
+ goto exit;
+ }
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ object = args[0];
+skip_optional:
+ return_value = builtin_vars_impl(module, object);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(builtin_sum__doc__,
"sum($module, iterable, /, start=0)\n"
"--\n"
@@ -1215,4 +1409,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=973da43fa65aa727 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0a6a8efe82cf8b81 input=a9049054013a1b77]*/