blob: b43ce64af0dc436cb1b729e9b87f9e57b0abe93a [file] [log] [blame]
Tal Einat3286ce42018-09-10 21:33:08 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(itertools_groupby__doc__,
6"groupby(iterable, key=None)\n"
7"--\n"
8"\n"
9"make an iterator that returns consecutive keys and groups from the iterable\n"
10"\n"
11" iterable\n"
12" Elements to divide into groups according to the key function.\n"
13" key\n"
14" A function for computing the group category for each element.\n"
15" If the key function is not specified or is None, the element itself\n"
16" is used for grouping.");
17
18static PyObject *
19itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc);
20
21static PyObject *
22itertools_groupby(PyTypeObject *type, PyObject *args, PyObject *kwargs)
23{
24 PyObject *return_value = NULL;
25 static const char * const _keywords[] = {"iterable", "key", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020026 static _PyArg_Parser _parser = {NULL, _keywords, "groupby", 0};
27 PyObject *argsbuf[2];
28 PyObject * const *fastargs;
29 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
30 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
Tal Einat3286ce42018-09-10 21:33:08 +030031 PyObject *it;
32 PyObject *keyfunc = Py_None;
33
Serhiy Storchaka31913912019-03-14 10:32:22 +020034 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
35 if (!fastargs) {
Tal Einat3286ce42018-09-10 21:33:08 +030036 goto exit;
37 }
Serhiy Storchaka31913912019-03-14 10:32:22 +020038 it = fastargs[0];
39 if (!noptargs) {
40 goto skip_optional_pos;
41 }
42 keyfunc = fastargs[1];
43skip_optional_pos:
Tal Einat3286ce42018-09-10 21:33:08 +030044 return_value = itertools_groupby_impl(type, it, keyfunc);
45
46exit:
47 return return_value;
48}
49
50static PyObject *
51itertools__grouper_impl(PyTypeObject *type, PyObject *parent,
52 PyObject *tgtkey);
53
54static PyObject *
55itertools__grouper(PyTypeObject *type, PyObject *args, PyObject *kwargs)
56{
57 PyObject *return_value = NULL;
58 PyObject *parent;
59 PyObject *tgtkey;
60
61 if ((type == &_grouper_type) &&
62 !_PyArg_NoKeywords("_grouper", kwargs)) {
63 goto exit;
64 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020065 if (!_PyArg_CheckPositional("_grouper", PyTuple_GET_SIZE(args), 2, 2)) {
Tal Einat3286ce42018-09-10 21:33:08 +030066 goto exit;
67 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020068 if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), &groupby_type)) {
69 _PyArg_BadArgument("_grouper", 1, (&groupby_type)->tp_name, PyTuple_GET_ITEM(args, 0));
70 goto exit;
71 }
72 parent = PyTuple_GET_ITEM(args, 0);
73 tgtkey = PyTuple_GET_ITEM(args, 1);
Tal Einat3286ce42018-09-10 21:33:08 +030074 return_value = itertools__grouper_impl(type, parent, tgtkey);
75
76exit:
77 return return_value;
78}
Tal Einatc4bccd32018-09-12 00:49:13 +030079
80PyDoc_STRVAR(itertools_teedataobject__doc__,
81"teedataobject(iterable, values, next, /)\n"
82"--\n"
83"\n"
84"Data container common to multiple tee objects.");
85
86static PyObject *
87itertools_teedataobject_impl(PyTypeObject *type, PyObject *it,
88 PyObject *values, PyObject *next);
89
90static PyObject *
91itertools_teedataobject(PyTypeObject *type, PyObject *args, PyObject *kwargs)
92{
93 PyObject *return_value = NULL;
94 PyObject *it;
95 PyObject *values;
96 PyObject *next;
97
98 if ((type == &teedataobject_type) &&
99 !_PyArg_NoKeywords("teedataobject", kwargs)) {
100 goto exit;
101 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200102 if (!_PyArg_CheckPositional("teedataobject", PyTuple_GET_SIZE(args), 3, 3)) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300103 goto exit;
104 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200105 it = PyTuple_GET_ITEM(args, 0);
106 if (!PyList_Check(PyTuple_GET_ITEM(args, 1))) {
107 _PyArg_BadArgument("teedataobject", 2, "list", PyTuple_GET_ITEM(args, 1));
108 goto exit;
109 }
110 values = PyTuple_GET_ITEM(args, 1);
111 next = PyTuple_GET_ITEM(args, 2);
Tal Einatc4bccd32018-09-12 00:49:13 +0300112 return_value = itertools_teedataobject_impl(type, it, values, next);
113
114exit:
115 return return_value;
116}
117
118PyDoc_STRVAR(itertools__tee__doc__,
119"_tee(iterable, /)\n"
120"--\n"
121"\n"
122"Iterator wrapped to make it copyable.");
123
124static PyObject *
125itertools__tee_impl(PyTypeObject *type, PyObject *iterable);
126
127static PyObject *
128itertools__tee(PyTypeObject *type, PyObject *args, PyObject *kwargs)
129{
130 PyObject *return_value = NULL;
131 PyObject *iterable;
132
133 if ((type == &tee_type) &&
134 !_PyArg_NoKeywords("_tee", kwargs)) {
135 goto exit;
136 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200137 if (!_PyArg_CheckPositional("_tee", PyTuple_GET_SIZE(args), 1, 1)) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300138 goto exit;
139 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200140 iterable = PyTuple_GET_ITEM(args, 0);
Tal Einatc4bccd32018-09-12 00:49:13 +0300141 return_value = itertools__tee_impl(type, iterable);
142
143exit:
144 return return_value;
145}
146
147PyDoc_STRVAR(itertools_tee__doc__,
148"tee($module, iterable, n=2, /)\n"
149"--\n"
150"\n"
151"Returns a tuple of n independent iterators.");
152
153#define ITERTOOLS_TEE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200154 {"tee", (PyCFunction)(void(*)(void))itertools_tee, METH_FASTCALL, itertools_tee__doc__},
Tal Einatc4bccd32018-09-12 00:49:13 +0300155
156static PyObject *
157itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n);
158
159static PyObject *
160itertools_tee(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
161{
162 PyObject *return_value = NULL;
163 PyObject *iterable;
164 Py_ssize_t n = 2;
165
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200166 if (!_PyArg_CheckPositional("tee", nargs, 1, 2)) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300167 goto exit;
168 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200169 iterable = args[0];
170 if (nargs < 2) {
171 goto skip_optional;
172 }
173 if (PyFloat_Check(args[1])) {
174 PyErr_SetString(PyExc_TypeError,
175 "integer argument expected, got float" );
176 goto exit;
177 }
178 {
179 Py_ssize_t ival = -1;
180 PyObject *iobj = PyNumber_Index(args[1]);
181 if (iobj != NULL) {
182 ival = PyLong_AsSsize_t(iobj);
183 Py_DECREF(iobj);
184 }
185 if (ival == -1 && PyErr_Occurred()) {
186 goto exit;
187 }
188 n = ival;
189 }
190skip_optional:
Tal Einatc4bccd32018-09-12 00:49:13 +0300191 return_value = itertools_tee_impl(module, iterable, n);
192
193exit:
194 return return_value;
195}
196
197PyDoc_STRVAR(itertools_cycle__doc__,
198"cycle(iterable, /)\n"
199"--\n"
200"\n"
201"Return elements from the iterable until it is exhausted. Then repeat the sequence indefinitely.");
202
203static PyObject *
204itertools_cycle_impl(PyTypeObject *type, PyObject *iterable);
205
206static PyObject *
207itertools_cycle(PyTypeObject *type, PyObject *args, PyObject *kwargs)
208{
209 PyObject *return_value = NULL;
210 PyObject *iterable;
211
212 if ((type == &cycle_type) &&
213 !_PyArg_NoKeywords("cycle", kwargs)) {
214 goto exit;
215 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200216 if (!_PyArg_CheckPositional("cycle", PyTuple_GET_SIZE(args), 1, 1)) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300217 goto exit;
218 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200219 iterable = PyTuple_GET_ITEM(args, 0);
Tal Einatc4bccd32018-09-12 00:49:13 +0300220 return_value = itertools_cycle_impl(type, iterable);
221
222exit:
223 return return_value;
224}
225
226PyDoc_STRVAR(itertools_dropwhile__doc__,
227"dropwhile(predicate, iterable, /)\n"
228"--\n"
229"\n"
230"Drop items from the iterable while predicate(item) is true.\n"
231"\n"
232"Afterwards, return every element until the iterable is exhausted.");
233
234static PyObject *
235itertools_dropwhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
236
237static PyObject *
238itertools_dropwhile(PyTypeObject *type, PyObject *args, PyObject *kwargs)
239{
240 PyObject *return_value = NULL;
241 PyObject *func;
242 PyObject *seq;
243
244 if ((type == &dropwhile_type) &&
245 !_PyArg_NoKeywords("dropwhile", kwargs)) {
246 goto exit;
247 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200248 if (!_PyArg_CheckPositional("dropwhile", PyTuple_GET_SIZE(args), 2, 2)) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300249 goto exit;
250 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200251 func = PyTuple_GET_ITEM(args, 0);
252 seq = PyTuple_GET_ITEM(args, 1);
Tal Einatc4bccd32018-09-12 00:49:13 +0300253 return_value = itertools_dropwhile_impl(type, func, seq);
254
255exit:
256 return return_value;
257}
258
259PyDoc_STRVAR(itertools_takewhile__doc__,
260"takewhile(predicate, iterable, /)\n"
261"--\n"
262"\n"
263"Return successive entries from an iterable as long as the predicate evaluates to true for each entry.");
264
265static PyObject *
266itertools_takewhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
267
268static PyObject *
269itertools_takewhile(PyTypeObject *type, PyObject *args, PyObject *kwargs)
270{
271 PyObject *return_value = NULL;
272 PyObject *func;
273 PyObject *seq;
274
275 if ((type == &takewhile_type) &&
276 !_PyArg_NoKeywords("takewhile", kwargs)) {
277 goto exit;
278 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200279 if (!_PyArg_CheckPositional("takewhile", PyTuple_GET_SIZE(args), 2, 2)) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300280 goto exit;
281 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200282 func = PyTuple_GET_ITEM(args, 0);
283 seq = PyTuple_GET_ITEM(args, 1);
Tal Einatc4bccd32018-09-12 00:49:13 +0300284 return_value = itertools_takewhile_impl(type, func, seq);
285
286exit:
287 return return_value;
288}
289
290PyDoc_STRVAR(itertools_starmap__doc__,
291"starmap(function, iterable, /)\n"
292"--\n"
293"\n"
294"Return an iterator whose values are returned from the function evaluated with an argument tuple taken from the given sequence.");
295
296static PyObject *
297itertools_starmap_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
298
299static PyObject *
300itertools_starmap(PyTypeObject *type, PyObject *args, PyObject *kwargs)
301{
302 PyObject *return_value = NULL;
303 PyObject *func;
304 PyObject *seq;
305
306 if ((type == &starmap_type) &&
307 !_PyArg_NoKeywords("starmap", kwargs)) {
308 goto exit;
309 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200310 if (!_PyArg_CheckPositional("starmap", PyTuple_GET_SIZE(args), 2, 2)) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300311 goto exit;
312 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200313 func = PyTuple_GET_ITEM(args, 0);
314 seq = PyTuple_GET_ITEM(args, 1);
Tal Einatc4bccd32018-09-12 00:49:13 +0300315 return_value = itertools_starmap_impl(type, func, seq);
316
317exit:
318 return return_value;
319}
320
321PyDoc_STRVAR(itertools_chain_from_iterable__doc__,
322"from_iterable($type, iterable, /)\n"
323"--\n"
324"\n"
325"Alternative chain() constructor taking a single iterable argument that evaluates lazily.");
326
327#define ITERTOOLS_CHAIN_FROM_ITERABLE_METHODDEF \
328 {"from_iterable", (PyCFunction)itertools_chain_from_iterable, METH_O|METH_CLASS, itertools_chain_from_iterable__doc__},
329
330PyDoc_STRVAR(itertools_combinations__doc__,
331"combinations(iterable, r)\n"
332"--\n"
333"\n"
334"Return successive r-length combinations of elements in the iterable.\n"
335"\n"
336"combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)");
337
338static PyObject *
339itertools_combinations_impl(PyTypeObject *type, PyObject *iterable,
340 Py_ssize_t r);
341
342static PyObject *
343itertools_combinations(PyTypeObject *type, PyObject *args, PyObject *kwargs)
344{
345 PyObject *return_value = NULL;
346 static const char * const _keywords[] = {"iterable", "r", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200347 static _PyArg_Parser _parser = {NULL, _keywords, "combinations", 0};
348 PyObject *argsbuf[2];
349 PyObject * const *fastargs;
350 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Tal Einatc4bccd32018-09-12 00:49:13 +0300351 PyObject *iterable;
352 Py_ssize_t r;
353
Serhiy Storchaka31913912019-03-14 10:32:22 +0200354 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
355 if (!fastargs) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300356 goto exit;
357 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200358 iterable = fastargs[0];
359 if (PyFloat_Check(fastargs[1])) {
360 PyErr_SetString(PyExc_TypeError,
361 "integer argument expected, got float" );
362 goto exit;
363 }
364 {
365 Py_ssize_t ival = -1;
366 PyObject *iobj = PyNumber_Index(fastargs[1]);
367 if (iobj != NULL) {
368 ival = PyLong_AsSsize_t(iobj);
369 Py_DECREF(iobj);
370 }
371 if (ival == -1 && PyErr_Occurred()) {
372 goto exit;
373 }
374 r = ival;
375 }
Tal Einatc4bccd32018-09-12 00:49:13 +0300376 return_value = itertools_combinations_impl(type, iterable, r);
377
378exit:
379 return return_value;
380}
381
382PyDoc_STRVAR(itertools_combinations_with_replacement__doc__,
383"combinations_with_replacement(iterable, r)\n"
384"--\n"
385"\n"
386"Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats.\n"
387"\n"
388"combinations_with_replacement(\'ABC\', 2) --> AA AB AC BB BC CC\"");
389
390static PyObject *
391itertools_combinations_with_replacement_impl(PyTypeObject *type,
392 PyObject *iterable,
393 Py_ssize_t r);
394
395static PyObject *
396itertools_combinations_with_replacement(PyTypeObject *type, PyObject *args, PyObject *kwargs)
397{
398 PyObject *return_value = NULL;
399 static const char * const _keywords[] = {"iterable", "r", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200400 static _PyArg_Parser _parser = {NULL, _keywords, "combinations_with_replacement", 0};
401 PyObject *argsbuf[2];
402 PyObject * const *fastargs;
403 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Tal Einatc4bccd32018-09-12 00:49:13 +0300404 PyObject *iterable;
405 Py_ssize_t r;
406
Serhiy Storchaka31913912019-03-14 10:32:22 +0200407 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
408 if (!fastargs) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300409 goto exit;
410 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200411 iterable = fastargs[0];
412 if (PyFloat_Check(fastargs[1])) {
413 PyErr_SetString(PyExc_TypeError,
414 "integer argument expected, got float" );
415 goto exit;
416 }
417 {
418 Py_ssize_t ival = -1;
419 PyObject *iobj = PyNumber_Index(fastargs[1]);
420 if (iobj != NULL) {
421 ival = PyLong_AsSsize_t(iobj);
422 Py_DECREF(iobj);
423 }
424 if (ival == -1 && PyErr_Occurred()) {
425 goto exit;
426 }
427 r = ival;
428 }
Tal Einatc4bccd32018-09-12 00:49:13 +0300429 return_value = itertools_combinations_with_replacement_impl(type, iterable, r);
430
431exit:
432 return return_value;
433}
434
435PyDoc_STRVAR(itertools_permutations__doc__,
436"permutations(iterable, r=None)\n"
437"--\n"
438"\n"
439"Return successive r-length permutations of elements in the iterable.\n"
440"\n"
441"permutations(range(3), 2) --> (0,1), (0,2), (1,0), (1,2), (2,0), (2,1)");
442
443static PyObject *
444itertools_permutations_impl(PyTypeObject *type, PyObject *iterable,
445 PyObject *robj);
446
447static PyObject *
448itertools_permutations(PyTypeObject *type, PyObject *args, PyObject *kwargs)
449{
450 PyObject *return_value = NULL;
451 static const char * const _keywords[] = {"iterable", "r", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200452 static _PyArg_Parser _parser = {NULL, _keywords, "permutations", 0};
453 PyObject *argsbuf[2];
454 PyObject * const *fastargs;
455 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
456 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
Tal Einatc4bccd32018-09-12 00:49:13 +0300457 PyObject *iterable;
458 PyObject *robj = Py_None;
459
Serhiy Storchaka31913912019-03-14 10:32:22 +0200460 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
461 if (!fastargs) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300462 goto exit;
463 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200464 iterable = fastargs[0];
465 if (!noptargs) {
466 goto skip_optional_pos;
467 }
468 robj = fastargs[1];
469skip_optional_pos:
Tal Einatc4bccd32018-09-12 00:49:13 +0300470 return_value = itertools_permutations_impl(type, iterable, robj);
471
472exit:
473 return return_value;
474}
475
476PyDoc_STRVAR(itertools_accumulate__doc__,
Lisa Roach9718b592018-09-23 17:34:59 -0700477"accumulate(iterable, func=None, *, initial=None)\n"
Tal Einatc4bccd32018-09-12 00:49:13 +0300478"--\n"
479"\n"
480"Return series of accumulated sums (or other binary function results).");
481
482static PyObject *
483itertools_accumulate_impl(PyTypeObject *type, PyObject *iterable,
Lisa Roach9718b592018-09-23 17:34:59 -0700484 PyObject *binop, PyObject *initial);
Tal Einatc4bccd32018-09-12 00:49:13 +0300485
486static PyObject *
487itertools_accumulate(PyTypeObject *type, PyObject *args, PyObject *kwargs)
488{
489 PyObject *return_value = NULL;
Lisa Roach9718b592018-09-23 17:34:59 -0700490 static const char * const _keywords[] = {"iterable", "func", "initial", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200491 static _PyArg_Parser _parser = {NULL, _keywords, "accumulate", 0};
492 PyObject *argsbuf[3];
493 PyObject * const *fastargs;
494 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
495 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
Tal Einatc4bccd32018-09-12 00:49:13 +0300496 PyObject *iterable;
497 PyObject *binop = Py_None;
Lisa Roach9718b592018-09-23 17:34:59 -0700498 PyObject *initial = Py_None;
Tal Einatc4bccd32018-09-12 00:49:13 +0300499
Serhiy Storchaka31913912019-03-14 10:32:22 +0200500 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
501 if (!fastargs) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300502 goto exit;
503 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200504 iterable = fastargs[0];
505 if (!noptargs) {
506 goto skip_optional_pos;
507 }
508 if (fastargs[1]) {
509 binop = fastargs[1];
510 if (!--noptargs) {
511 goto skip_optional_pos;
512 }
513 }
514skip_optional_pos:
515 if (!noptargs) {
516 goto skip_optional_kwonly;
517 }
518 initial = fastargs[2];
519skip_optional_kwonly:
Lisa Roach9718b592018-09-23 17:34:59 -0700520 return_value = itertools_accumulate_impl(type, iterable, binop, initial);
Tal Einatc4bccd32018-09-12 00:49:13 +0300521
522exit:
523 return return_value;
524}
525
526PyDoc_STRVAR(itertools_compress__doc__,
527"compress(data, selectors)\n"
528"--\n"
529"\n"
530"Return data elements corresponding to true selector elements.\n"
531"\n"
532"Forms a shorter iterator from selected data elements using the selectors to\n"
533"choose the data elements.");
534
535static PyObject *
536itertools_compress_impl(PyTypeObject *type, PyObject *seq1, PyObject *seq2);
537
538static PyObject *
539itertools_compress(PyTypeObject *type, PyObject *args, PyObject *kwargs)
540{
541 PyObject *return_value = NULL;
542 static const char * const _keywords[] = {"data", "selectors", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200543 static _PyArg_Parser _parser = {NULL, _keywords, "compress", 0};
544 PyObject *argsbuf[2];
545 PyObject * const *fastargs;
546 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Tal Einatc4bccd32018-09-12 00:49:13 +0300547 PyObject *seq1;
548 PyObject *seq2;
549
Serhiy Storchaka31913912019-03-14 10:32:22 +0200550 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
551 if (!fastargs) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300552 goto exit;
553 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200554 seq1 = fastargs[0];
555 seq2 = fastargs[1];
Tal Einatc4bccd32018-09-12 00:49:13 +0300556 return_value = itertools_compress_impl(type, seq1, seq2);
557
558exit:
559 return return_value;
560}
561
562PyDoc_STRVAR(itertools_filterfalse__doc__,
563"filterfalse(function, iterable, /)\n"
564"--\n"
565"\n"
566"Return those items of iterable for which function(item) is false.\n"
567"\n"
568"If function is None, return the items that are false.");
569
570static PyObject *
571itertools_filterfalse_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
572
573static PyObject *
574itertools_filterfalse(PyTypeObject *type, PyObject *args, PyObject *kwargs)
575{
576 PyObject *return_value = NULL;
577 PyObject *func;
578 PyObject *seq;
579
580 if ((type == &filterfalse_type) &&
581 !_PyArg_NoKeywords("filterfalse", kwargs)) {
582 goto exit;
583 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200584 if (!_PyArg_CheckPositional("filterfalse", PyTuple_GET_SIZE(args), 2, 2)) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300585 goto exit;
586 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200587 func = PyTuple_GET_ITEM(args, 0);
588 seq = PyTuple_GET_ITEM(args, 1);
Tal Einatc4bccd32018-09-12 00:49:13 +0300589 return_value = itertools_filterfalse_impl(type, func, seq);
590
591exit:
592 return return_value;
593}
594
595PyDoc_STRVAR(itertools_count__doc__,
596"count(start=0, step=1)\n"
597"--\n"
598"\n"
599"Return a count object whose .__next__() method returns consecutive values.\n"
600"\n"
601"Equivalent to:\n"
602" def count(firstval=0, step=1):\n"
603" x = firstval\n"
604" while 1:\n"
605" yield x\n"
606" x += step");
607
608static PyObject *
609itertools_count_impl(PyTypeObject *type, PyObject *long_cnt,
610 PyObject *long_step);
611
612static PyObject *
613itertools_count(PyTypeObject *type, PyObject *args, PyObject *kwargs)
614{
615 PyObject *return_value = NULL;
616 static const char * const _keywords[] = {"start", "step", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200617 static _PyArg_Parser _parser = {NULL, _keywords, "count", 0};
618 PyObject *argsbuf[2];
619 PyObject * const *fastargs;
620 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
621 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
Tal Einatc4bccd32018-09-12 00:49:13 +0300622 PyObject *long_cnt = NULL;
623 PyObject *long_step = NULL;
624
Serhiy Storchaka31913912019-03-14 10:32:22 +0200625 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
626 if (!fastargs) {
Tal Einatc4bccd32018-09-12 00:49:13 +0300627 goto exit;
628 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200629 if (!noptargs) {
630 goto skip_optional_pos;
631 }
632 if (fastargs[0]) {
633 long_cnt = fastargs[0];
634 if (!--noptargs) {
635 goto skip_optional_pos;
636 }
637 }
638 long_step = fastargs[1];
639skip_optional_pos:
Tal Einatc4bccd32018-09-12 00:49:13 +0300640 return_value = itertools_count_impl(type, long_cnt, long_step);
641
642exit:
643 return return_value;
644}
Serhiy Storchaka31913912019-03-14 10:32:22 +0200645/*[clinic end generated code: output=04c49debcae96003 input=a9049054013a1b77]*/