summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorTal Einat <taleinat+github@gmail.com>2018-09-10 18:33:08 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-09-10 18:33:08 (GMT)
commit3286ce4adee85c5ce8ab3ee3089f3cd44a017fd7 (patch)
tree991e08da85fe97ff456c90d9a984fa8cda11d869 /Modules/itertoolsmodule.c
parent9430652535f88125d8003f342a8884d34885d876 (diff)
downloadcpython-3286ce4adee85c5ce8ab3ee3089f3cd44a017fd7.zip
cpython-3286ce4adee85c5ce8ab3ee3089f3cd44a017fd7.tar.gz
cpython-3286ce4adee85c5ce8ab3ee3089f3cd44a017fd7.tar.bz2
bpo-20180: itertools.groupby Argument Clinic conversion (GH-4170)
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c64
1 files changed, 41 insertions, 23 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 8a36755..3ad7e5c 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -7,6 +7,17 @@
by Raymond D. Hettinger <python@rcn.com>
*/
+/*[clinic input]
+module itertools
+class itertools.groupby "groupbyobject *" "&groupby_type"
+class itertools._grouper "_grouperobject *" "&_grouper_type"
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=9d506f5bb9177570]*/
+
+static PyTypeObject groupby_type;
+static PyTypeObject _grouper_type;
+#include "clinic/itertoolsmodule.c.h"
+
/* groupby object ************************************************************/
@@ -20,19 +31,27 @@ typedef struct {
const void *currgrouper; /* borrowed reference */
} groupbyobject;
-static PyTypeObject groupby_type;
static PyObject *_grouper_create(groupbyobject *, PyObject *);
+/*[clinic input]
+@classmethod
+itertools.groupby.__new__
+
+ iterable as it: object
+ Elements to divide into groups according to the key function.
+ key as keyfunc: object = None
+ A function for computing the group category for each element.
+ If the key function is not specified or is None, the element itself
+ is used for grouping.
+
+make an iterator that returns consecutive keys and groups from the iterable
+[clinic start generated code]*/
+
static PyObject *
-groupby_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc)
+/*[clinic end generated code: output=cbb1ae3a90fd4141 input=6b3d123e87ff65a1]*/
{
- static char *kwargs[] = {"iterable", "key", NULL};
groupbyobject *gbo;
- PyObject *it, *keyfunc = Py_None;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:groupby", kwargs,
- &it, &keyfunc))
- return NULL;
gbo = (groupbyobject *)type->tp_alloc(type, 0);
if (gbo == NULL)
@@ -186,11 +205,6 @@ static PyMethodDef groupby_methods[] = {
{NULL, NULL} /* sentinel */
};
-PyDoc_STRVAR(groupby_doc,
-"groupby(iterable, key=None) -> make an iterator that returns consecutive\n\
-keys and groups from the iterable. If the key function is not specified or\n\
-is None, the element itself is used for grouping.\n");
-
static PyTypeObject groupby_type = {
PyVarObject_HEAD_INIT(NULL, 0)
"itertools.groupby", /* tp_name */
@@ -214,7 +228,7 @@ static PyTypeObject groupby_type = {
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
- groupby_doc, /* tp_doc */
+ itertools_groupby__doc__, /* tp_doc */
(traverseproc)groupby_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
@@ -231,7 +245,7 @@ static PyTypeObject groupby_type = {
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
- groupby_new, /* tp_new */
+ itertools_groupby, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
@@ -244,16 +258,20 @@ typedef struct {
PyObject *tgtkey;
} _grouperobject;
-static PyTypeObject _grouper_type;
+/*[clinic input]
+@classmethod
+itertools._grouper.__new__
+
+ parent: object(subclass_of='&groupby_type')
+ tgtkey: object
+ /
+[clinic start generated code]*/
static PyObject *
-_grouper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+itertools__grouper_impl(PyTypeObject *type, PyObject *parent,
+ PyObject *tgtkey)
+/*[clinic end generated code: output=462efb1cdebb5914 input=dc180d7771fc8c59]*/
{
- PyObject *parent, *tgtkey;
-
- if (!PyArg_ParseTuple(args, "O!O", &groupby_type, &parent, &tgtkey))
- return NULL;
-
return _grouper_create((groupbyobject*) parent, tgtkey);
}
@@ -374,7 +392,7 @@ static PyTypeObject _grouper_type = {
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
- _grouper_new, /* tp_new */
+ itertools__grouper, /* tp_new */
PyObject_GC_Del, /* tp_free */
};