FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-20180: itertools.groupby Argument Clinic conversion by taleinat · Pull Request #4170 · python/cpython · GitHub

Repository navigation

64 changes: 64 additions & 0 deletions Modules/clinic/itertoolsmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 41 additions & 23 deletions Modules/itertoolsmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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 ************************************************************/

Expand All @@ -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)
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
};

Expand All @@ -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);
}

Expand Down Expand Up @@ -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 */
};

Expand Down

Back | FazBrowse Home | New Git URL