bpo-20180: itertools.groupby Argument Clinic conversion (GH-4170) · python/cpython@3286ce4 (original) (raw)

`@@ -7,6 +7,17 @@

`

7

7

` by Raymond D. Hettinger python@rcn.com

`

8

8

`*/

`

9

9

``

``

10

`+

/*[clinic input]

`

``

11

`+

module itertools

`

``

12

`+

class itertools.groupby "groupbyobject *" "&groupby_type"

`

``

13

`+

class itertools._grouper "_grouperobject *" "&_grouper_type"

`

``

14

`+

[clinic start generated code]*/

`

``

15

`+

/[clinic end generated code: output=da39a3ee5e6b4b0d input=9d506f5bb9177570]/

`

``

16

+

``

17

`+

static PyTypeObject groupby_type;

`

``

18

`+

static PyTypeObject _grouper_type;

`

``

19

`+

#include "clinic/itertoolsmodule.c.h"

`

``

20

+

10

21

``

11

22

`/* groupby object ************************************************************/

`

12

23

``

`@@ -20,19 +31,27 @@ typedef struct {

`

20

31

`const void currgrouper; / borrowed reference */

`

21

32

`} groupbyobject;

`

22

33

``

23

``

`-

static PyTypeObject groupby_type;

`

24

34

`static PyObject *_grouper_create(groupbyobject *, PyObject *);

`

25

35

``

``

36

`+

/*[clinic input]

`

``

37

`+

@classmethod

`

``

38

`+

itertools.groupby.new

`

``

39

+

``

40

`+

iterable as it: object

`

``

41

`+

Elements to divide into groups according to the key function.

`

``

42

`+

key as keyfunc: object = None

`

``

43

`+

A function for computing the group category for each element.

`

``

44

`+

If the key function is not specified or is None, the element itself

`

``

45

`+

is used for grouping.

`

``

46

+

``

47

`+

make an iterator that returns consecutive keys and groups from the iterable

`

``

48

`+

[clinic start generated code]*/

`

``

49

+

26

50

`static PyObject *

`

27

``

`-

groupby_new(PyTypeObject *type, PyObject *args, PyObject *kwds)

`

``

51

`+

itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc)

`

``

52

`+

/[clinic end generated code: output=cbb1ae3a90fd4141 input=6b3d123e87ff65a1]/

`

28

53

`{

`

29

``

`-

static char *kwargs[] = {"iterable", "key", NULL};

`

30

54

`groupbyobject *gbo;

`

31

``

`-

PyObject *it, *keyfunc = Py_None;

`

32

``

-

33

``

`-

if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:groupby", kwargs,

`

34

``

`-

&it, &keyfunc))

`

35

``

`-

return NULL;

`

36

55

``

37

56

`gbo = (groupbyobject *)type->tp_alloc(type, 0);

`

38

57

`if (gbo == NULL)

`

`@@ -186,11 +205,6 @@ static PyMethodDef groupby_methods[] = {

`

186

205

` {NULL, NULL} /* sentinel */

`

187

206

`};

`

188

207

``

189

``

`-

PyDoc_STRVAR(groupby_doc,

`

190

``

`-

"groupby(iterable, key=None) -> make an iterator that returns consecutive\n\

`

191

``

`-

keys and groups from the iterable. If the key function is not specified or\n\

`

192

``

`-

is None, the element itself is used for grouping.\n");

`

193

``

-

194

208

`static PyTypeObject groupby_type = {

`

195

209

`PyVarObject_HEAD_INIT(NULL, 0)

`

196

210

`"itertools.groupby", /* tp_name */

`

`@@ -214,7 +228,7 @@ static PyTypeObject groupby_type = {

`

214

228

`0, /* tp_as_buffer */

`

215

229

`Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |

`

216

230

`Py_TPFLAGS_BASETYPE, /* tp_flags */

`

217

``

`-

groupby_doc, /* tp_doc */

`

``

231

`+

itertools_groupby__doc__, /* tp_doc */

`

218

232

` (traverseproc)groupby_traverse, /* tp_traverse */

`

219

233

`0, /* tp_clear */

`

220

234

`0, /* tp_richcompare */

`

`@@ -231,7 +245,7 @@ static PyTypeObject groupby_type = {

`

231

245

`0, /* tp_dictoffset */

`

232

246

`0, /* tp_init */

`

233

247

`0, /* tp_alloc */

`

234

``

`-

groupby_new, /* tp_new */

`

``

248

`+

itertools_groupby, /* tp_new */

`

235

249

`PyObject_GC_Del, /* tp_free */

`

236

250

`};

`

237

251

``

`@@ -244,16 +258,20 @@ typedef struct {

`

244

258

`PyObject *tgtkey;

`

245

259

`} _grouperobject;

`

246

260

``

247

``

`-

static PyTypeObject _grouper_type;

`

``

261

`+

/*[clinic input]

`

``

262

`+

@classmethod

`

``

263

`+

itertools._grouper.new

`

``

264

+

``

265

`+

parent: object(subclass_of='&groupby_type')

`

``

266

`+

tgtkey: object

`

``

267

`+

/

`

``

268

`+

[clinic start generated code]*/

`

248

269

``

249

270

`static PyObject *

`

250

``

`-

_grouper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)

`

``

271

`+

itertools__grouper_impl(PyTypeObject *type, PyObject *parent,

`

``

272

`+

PyObject *tgtkey)

`

``

273

`+

/[clinic end generated code: output=462efb1cdebb5914 input=dc180d7771fc8c59]/

`

251

274

`{

`

252

``

`-

PyObject *parent, *tgtkey;

`

253

``

-

254

``

`-

if (!PyArg_ParseTuple(args, "O!O", &groupby_type, &parent, &tgtkey))

`

255

``

`-

return NULL;

`

256

``

-

257

275

`return _grouper_create((groupbyobject*) parent, tgtkey);

`

258

276

`}

`

259

277

``

`@@ -374,7 +392,7 @@ static PyTypeObject _grouper_type = {

`

374

392

`0, /* tp_dictoffset */

`

375

393

`0, /* tp_init */

`

376

394

`0, /* tp_alloc */

`

377

``

`-

_grouper_new, /* tp_new */

`

``

395

`+

itertools__grouper, /* tp_new */

`

378

396

`PyObject_GC_Del, /* tp_free */

`

379

397

`};

`

380

398

``