Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/Modules/clinic/itertoolsmodule.c.h
Line
Count
Source (jump to first uncovered line)
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
PyDoc_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
18
static PyObject *
19
itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc);
20
21
static PyObject *
22
itertools_groupby(PyTypeObject *type, PyObject *args, PyObject *kwargs)
23
0
{
24
0
    PyObject *return_value = NULL;
25
0
    static const char * const _keywords[] = {"iterable", "key", NULL};
26
0
    static _PyArg_Parser _parser = {NULL, _keywords, "groupby", 0};
27
0
    PyObject *argsbuf[2];
28
0
    PyObject * const *fastargs;
29
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
30
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
31
0
    PyObject *it;
32
0
    PyObject *keyfunc = Py_None;
33
34
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
35
0
    if (!fastargs) {
36
0
        goto exit;
37
0
    }
38
0
    it = fastargs[0];
39
0
    if (!noptargs) {
40
0
        goto skip_optional_pos;
41
0
    }
42
0
    keyfunc = fastargs[1];
43
0
skip_optional_pos:
44
0
    return_value = itertools_groupby_impl(type, it, keyfunc);
45
46
0
exit:
47
0
    return return_value;
48
0
}
49
50
static PyObject *
51
itertools__grouper_impl(PyTypeObject *type, PyObject *parent,
52
                        PyObject *tgtkey);
53
54
static PyObject *
55
itertools__grouper(PyTypeObject *type, PyObject *args, PyObject *kwargs)
56
0
{
57
0
    PyObject *return_value = NULL;
58
0
    PyObject *parent;
59
0
    PyObject *tgtkey;
60
61
0
    if ((type == &_grouper_type) &&
62
0
        !_PyArg_NoKeywords("_grouper", kwargs)) {
63
0
        goto exit;
64
0
    }
65
0
    if (!_PyArg_CheckPositional("_grouper", PyTuple_GET_SIZE(args), 2, 2)) {
66
0
        goto exit;
67
0
    }
68
0
    if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), &groupby_type)) {
69
0
        _PyArg_BadArgument("_grouper", "argument 1", (&groupby_type)->tp_name, PyTuple_GET_ITEM(args, 0));
70
0
        goto exit;
71
0
    }
72
0
    parent = PyTuple_GET_ITEM(args, 0);
73
0
    tgtkey = PyTuple_GET_ITEM(args, 1);
74
0
    return_value = itertools__grouper_impl(type, parent, tgtkey);
75
76
0
exit:
77
0
    return return_value;
78
0
}
79
80
PyDoc_STRVAR(itertools_teedataobject__doc__,
81
"teedataobject(iterable, values, next, /)\n"
82
"--\n"
83
"\n"
84
"Data container common to multiple tee objects.");
85
86
static PyObject *
87
itertools_teedataobject_impl(PyTypeObject *type, PyObject *it,
88
                             PyObject *values, PyObject *next);
89
90
static PyObject *
91
itertools_teedataobject(PyTypeObject *type, PyObject *args, PyObject *kwargs)
92
0
{
93
0
    PyObject *return_value = NULL;
94
0
    PyObject *it;
95
0
    PyObject *values;
96
0
    PyObject *next;
97
98
0
    if ((type == &teedataobject_type) &&
99
0
        !_PyArg_NoKeywords("teedataobject", kwargs)) {
100
0
        goto exit;
101
0
    }
102
0
    if (!_PyArg_CheckPositional("teedataobject", PyTuple_GET_SIZE(args), 3, 3)) {
103
0
        goto exit;
104
0
    }
105
0
    it = PyTuple_GET_ITEM(args, 0);
106
0
    if (!PyList_Check(PyTuple_GET_ITEM(args, 1))) {
107
0
        _PyArg_BadArgument("teedataobject", "argument 2", "list", PyTuple_GET_ITEM(args, 1));
108
0
        goto exit;
109
0
    }
110
0
    values = PyTuple_GET_ITEM(args, 1);
111
0
    next = PyTuple_GET_ITEM(args, 2);
112
0
    return_value = itertools_teedataobject_impl(type, it, values, next);
113
114
0
exit:
115
0
    return return_value;
116
0
}
117
118
PyDoc_STRVAR(itertools__tee__doc__,
119
"_tee(iterable, /)\n"
120
"--\n"
121
"\n"
122
"Iterator wrapped to make it copyable.");
123
124
static PyObject *
125
itertools__tee_impl(PyTypeObject *type, PyObject *iterable);
126
127
static PyObject *
128
itertools__tee(PyTypeObject *type, PyObject *args, PyObject *kwargs)
129
0
{
130
0
    PyObject *return_value = NULL;
131
0
    PyObject *iterable;
132
133
0
    if ((type == &tee_type) &&
134
0
        !_PyArg_NoKeywords("_tee", kwargs)) {
135
0
        goto exit;
136
0
    }
137
0
    if (!_PyArg_CheckPositional("_tee", PyTuple_GET_SIZE(args), 1, 1)) {
138
0
        goto exit;
139
0
    }
140
0
    iterable = PyTuple_GET_ITEM(args, 0);
141
0
    return_value = itertools__tee_impl(type, iterable);
142
143
0
exit:
144
0
    return return_value;
145
0
}
146
147
PyDoc_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    \
154
    {"tee", (PyCFunction)(void(*)(void))itertools_tee, METH_FASTCALL, itertools_tee__doc__},
155
156
static PyObject *
157
itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n);
158
159
static PyObject *
160
itertools_tee(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
161
0
{
162
0
    PyObject *return_value = NULL;
163
0
    PyObject *iterable;
164
0
    Py_ssize_t n = 2;
165
166
0
    if (!_PyArg_CheckPositional("tee", nargs, 1, 2)) {
167
0
        goto exit;
168
0
    }
169
0
    iterable = args[0];
170
0
    if (nargs < 2) {
171
0
        goto skip_optional;
172
0
    }
173
0
    if (PyFloat_Check(args[1])) {
174
0
        PyErr_SetString(PyExc_TypeError,
175
0
                        "integer argument expected, got float" );
176
0
        goto exit;
177
0
    }
178
0
    {
179
0
        Py_ssize_t ival = -1;
180
0
        PyObject *iobj = PyNumber_Index(args[1]);
181
0
        if (iobj != NULL) {
182
0
            ival = PyLong_AsSsize_t(iobj);
183
0
            Py_DECREF(iobj);
184
0
        }
185
0
        if (ival == -1 && PyErr_Occurred()) {
186
0
            goto exit;
187
0
        }
188
0
        n = ival;
189
0
    }
190
0
skip_optional:
191
0
    return_value = itertools_tee_impl(module, iterable, n);
192
193
0
exit:
194
0
    return return_value;
195
0
}
196
197
PyDoc_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
203
static PyObject *
204
itertools_cycle_impl(PyTypeObject *type, PyObject *iterable);
205
206
static PyObject *
207
itertools_cycle(PyTypeObject *type, PyObject *args, PyObject *kwargs)
208
0
{
209
0
    PyObject *return_value = NULL;
210
0
    PyObject *iterable;
211
212
0
    if ((type == &cycle_type) &&
213
0
        !_PyArg_NoKeywords("cycle", kwargs)) {
214
0
        goto exit;
215
0
    }
216
0
    if (!_PyArg_CheckPositional("cycle", PyTuple_GET_SIZE(args), 1, 1)) {
217
0
        goto exit;
218
0
    }
219
0
    iterable = PyTuple_GET_ITEM(args, 0);
220
0
    return_value = itertools_cycle_impl(type, iterable);
221
222
0
exit:
223
0
    return return_value;
224
0
}
225
226
PyDoc_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
234
static PyObject *
235
itertools_dropwhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
236
237
static PyObject *
238
itertools_dropwhile(PyTypeObject *type, PyObject *args, PyObject *kwargs)
239
0
{
240
0
    PyObject *return_value = NULL;
241
0
    PyObject *func;
242
0
    PyObject *seq;
243
244
0
    if ((type == &dropwhile_type) &&
245
0
        !_PyArg_NoKeywords("dropwhile", kwargs)) {
246
0
        goto exit;
247
0
    }
248
0
    if (!_PyArg_CheckPositional("dropwhile", PyTuple_GET_SIZE(args), 2, 2)) {
249
0
        goto exit;
250
0
    }
251
0
    func = PyTuple_GET_ITEM(args, 0);
252
0
    seq = PyTuple_GET_ITEM(args, 1);
253
0
    return_value = itertools_dropwhile_impl(type, func, seq);
254
255
0
exit:
256
0
    return return_value;
257
0
}
258
259
PyDoc_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
265
static PyObject *
266
itertools_takewhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
267
268
static PyObject *
269
itertools_takewhile(PyTypeObject *type, PyObject *args, PyObject *kwargs)
270
0
{
271
0
    PyObject *return_value = NULL;
272
0
    PyObject *func;
273
0
    PyObject *seq;
274
275
0
    if ((type == &takewhile_type) &&
276
0
        !_PyArg_NoKeywords("takewhile", kwargs)) {
277
0
        goto exit;
278
0
    }
279
0
    if (!_PyArg_CheckPositional("takewhile", PyTuple_GET_SIZE(args), 2, 2)) {
280
0
        goto exit;
281
0
    }
282
0
    func = PyTuple_GET_ITEM(args, 0);
283
0
    seq = PyTuple_GET_ITEM(args, 1);
284
0
    return_value = itertools_takewhile_impl(type, func, seq);
285
286
0
exit:
287
0
    return return_value;
288
0
}
289
290
PyDoc_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
296
static PyObject *
297
itertools_starmap_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
298
299
static PyObject *
300
itertools_starmap(PyTypeObject *type, PyObject *args, PyObject *kwargs)
301
0
{
302
0
    PyObject *return_value = NULL;
303
0
    PyObject *func;
304
0
    PyObject *seq;
305
306
0
    if ((type == &starmap_type) &&
307
0
        !_PyArg_NoKeywords("starmap", kwargs)) {
308
0
        goto exit;
309
0
    }
310
0
    if (!_PyArg_CheckPositional("starmap", PyTuple_GET_SIZE(args), 2, 2)) {
311
0
        goto exit;
312
0
    }
313
0
    func = PyTuple_GET_ITEM(args, 0);
314
0
    seq = PyTuple_GET_ITEM(args, 1);
315
0
    return_value = itertools_starmap_impl(type, func, seq);
316
317
0
exit:
318
0
    return return_value;
319
0
}
320
321
PyDoc_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
330
PyDoc_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
338
static PyObject *
339
itertools_combinations_impl(PyTypeObject *type, PyObject *iterable,
340
                            Py_ssize_t r);
341
342
static PyObject *
343
itertools_combinations(PyTypeObject *type, PyObject *args, PyObject *kwargs)
344
0
{
345
0
    PyObject *return_value = NULL;
346
0
    static const char * const _keywords[] = {"iterable", "r", NULL};
347
0
    static _PyArg_Parser _parser = {NULL, _keywords, "combinations", 0};
348
0
    PyObject *argsbuf[2];
349
0
    PyObject * const *fastargs;
350
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
351
0
    PyObject *iterable;
352
0
    Py_ssize_t r;
353
354
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
355
0
    if (!fastargs) {
356
0
        goto exit;
357
0
    }
358
0
    iterable = fastargs[0];
359
0
    if (PyFloat_Check(fastargs[1])) {
360
0
        PyErr_SetString(PyExc_TypeError,
361
0
                        "integer argument expected, got float" );
362
0
        goto exit;
363
0
    }
364
0
    {
365
0
        Py_ssize_t ival = -1;
366
0
        PyObject *iobj = PyNumber_Index(fastargs[1]);
367
0
        if (iobj != NULL) {
368
0
            ival = PyLong_AsSsize_t(iobj);
369
0
            Py_DECREF(iobj);
370
0
        }
371
0
        if (ival == -1 && PyErr_Occurred()) {
372
0
            goto exit;
373
0
        }
374
0
        r = ival;
375
0
    }
376
0
    return_value = itertools_combinations_impl(type, iterable, r);
377
378
0
exit:
379
0
    return return_value;
380
0
}
381
382
PyDoc_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
390
static PyObject *
391
itertools_combinations_with_replacement_impl(PyTypeObject *type,
392
                                             PyObject *iterable,
393
                                             Py_ssize_t r);
394
395
static PyObject *
396
itertools_combinations_with_replacement(PyTypeObject *type, PyObject *args, PyObject *kwargs)
397
0
{
398
0
    PyObject *return_value = NULL;
399
0
    static const char * const _keywords[] = {"iterable", "r", NULL};
400
0
    static _PyArg_Parser _parser = {NULL, _keywords, "combinations_with_replacement", 0};
401
0
    PyObject *argsbuf[2];
402
0
    PyObject * const *fastargs;
403
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
404
0
    PyObject *iterable;
405
0
    Py_ssize_t r;
406
407
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
408
0
    if (!fastargs) {
409
0
        goto exit;
410
0
    }
411
0
    iterable = fastargs[0];
412
0
    if (PyFloat_Check(fastargs[1])) {
413
0
        PyErr_SetString(PyExc_TypeError,
414
0
                        "integer argument expected, got float" );
415
0
        goto exit;
416
0
    }
417
0
    {
418
0
        Py_ssize_t ival = -1;
419
0
        PyObject *iobj = PyNumber_Index(fastargs[1]);
420
0
        if (iobj != NULL) {
421
0
            ival = PyLong_AsSsize_t(iobj);
422
0
            Py_DECREF(iobj);
423
0
        }
424
0
        if (ival == -1 && PyErr_Occurred()) {
425
0
            goto exit;
426
0
        }
427
0
        r = ival;
428
0
    }
429
0
    return_value = itertools_combinations_with_replacement_impl(type, iterable, r);
430
431
0
exit:
432
0
    return return_value;
433
0
}
434
435
PyDoc_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
443
static PyObject *
444
itertools_permutations_impl(PyTypeObject *type, PyObject *iterable,
445
                            PyObject *robj);
446
447
static PyObject *
448
itertools_permutations(PyTypeObject *type, PyObject *args, PyObject *kwargs)
449
18
{
450
18
    PyObject *return_value = NULL;
451
18
    static const char * const _keywords[] = {"iterable", "r", NULL};
452
18
    static _PyArg_Parser _parser = {NULL, _keywords, "permutations", 0};
453
18
    PyObject *argsbuf[2];
454
18
    PyObject * const *fastargs;
455
18
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
456
18
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
457
18
    PyObject *iterable;
458
18
    PyObject *robj = Py_None;
459
460
18
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
461
18
    if (!fastargs) {
462
0
        goto exit;
463
0
    }
464
18
    iterable = fastargs[0];
465
18
    if (!noptargs) {
466
18
        goto skip_optional_pos;
467
18
    }
468
0
    robj = fastargs[1];
469
18
skip_optional_pos:
470
18
    return_value = itertools_permutations_impl(type, iterable, robj);
471
472
18
exit:
473
18
    return return_value;
474
18
}
475
476
PyDoc_STRVAR(itertools_accumulate__doc__,
477
"accumulate(iterable, func=None, *, initial=None)\n"
478
"--\n"
479
"\n"
480
"Return series of accumulated sums (or other binary function results).");
481
482
static PyObject *
483
itertools_accumulate_impl(PyTypeObject *type, PyObject *iterable,
484
                          PyObject *binop, PyObject *initial);
485
486
static PyObject *
487
itertools_accumulate(PyTypeObject *type, PyObject *args, PyObject *kwargs)
488
0
{
489
0
    PyObject *return_value = NULL;
490
0
    static const char * const _keywords[] = {"iterable", "func", "initial", NULL};
491
0
    static _PyArg_Parser _parser = {NULL, _keywords, "accumulate", 0};
492
0
    PyObject *argsbuf[3];
493
0
    PyObject * const *fastargs;
494
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
495
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
496
0
    PyObject *iterable;
497
0
    PyObject *binop = Py_None;
498
0
    PyObject *initial = Py_None;
499
500
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
501
0
    if (!fastargs) {
502
0
        goto exit;
503
0
    }
504
0
    iterable = fastargs[0];
505
0
    if (!noptargs) {
506
0
        goto skip_optional_pos;
507
0
    }
508
0
    if (fastargs[1]) {
509
0
        binop = fastargs[1];
510
0
        if (!--noptargs) {
511
0
            goto skip_optional_pos;
512
0
        }
513
0
    }
514
0
skip_optional_pos:
515
0
    if (!noptargs) {
516
0
        goto skip_optional_kwonly;
517
0
    }
518
0
    initial = fastargs[2];
519
0
skip_optional_kwonly:
520
0
    return_value = itertools_accumulate_impl(type, iterable, binop, initial);
521
522
0
exit:
523
0
    return return_value;
524
0
}
525
526
PyDoc_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
535
static PyObject *
536
itertools_compress_impl(PyTypeObject *type, PyObject *seq1, PyObject *seq2);
537
538
static PyObject *
539
itertools_compress(PyTypeObject *type, PyObject *args, PyObject *kwargs)
540
0
{
541
0
    PyObject *return_value = NULL;
542
0
    static const char * const _keywords[] = {"data", "selectors", NULL};
543
0
    static _PyArg_Parser _parser = {NULL, _keywords, "compress", 0};
544
0
    PyObject *argsbuf[2];
545
0
    PyObject * const *fastargs;
546
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
547
0
    PyObject *seq1;
548
0
    PyObject *seq2;
549
550
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
551
0
    if (!fastargs) {
552
0
        goto exit;
553
0
    }
554
0
    seq1 = fastargs[0];
555
0
    seq2 = fastargs[1];
556
0
    return_value = itertools_compress_impl(type, seq1, seq2);
557
558
0
exit:
559
0
    return return_value;
560
0
}
561
562
PyDoc_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
570
static PyObject *
571
itertools_filterfalse_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
572
573
static PyObject *
574
itertools_filterfalse(PyTypeObject *type, PyObject *args, PyObject *kwargs)
575
0
{
576
0
    PyObject *return_value = NULL;
577
0
    PyObject *func;
578
0
    PyObject *seq;
579
580
0
    if ((type == &filterfalse_type) &&
581
0
        !_PyArg_NoKeywords("filterfalse", kwargs)) {
582
0
        goto exit;
583
0
    }
584
0
    if (!_PyArg_CheckPositional("filterfalse", PyTuple_GET_SIZE(args), 2, 2)) {
585
0
        goto exit;
586
0
    }
587
0
    func = PyTuple_GET_ITEM(args, 0);
588
0
    seq = PyTuple_GET_ITEM(args, 1);
589
0
    return_value = itertools_filterfalse_impl(type, func, seq);
590
591
0
exit:
592
0
    return return_value;
593
0
}
594
595
PyDoc_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
608
static PyObject *
609
itertools_count_impl(PyTypeObject *type, PyObject *long_cnt,
610
                     PyObject *long_step);
611
612
static PyObject *
613
itertools_count(PyTypeObject *type, PyObject *args, PyObject *kwargs)
614
2
{
615
2
    PyObject *return_value = NULL;
616
2
    static const char * const _keywords[] = {"start", "step", NULL};
617
2
    static _PyArg_Parser _parser = {NULL, _keywords, "count", 0};
618
2
    PyObject *argsbuf[2];
619
2
    PyObject * const *fastargs;
620
2
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
621
2
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
622
2
    PyObject *long_cnt = NULL;
623
2
    PyObject *long_step = NULL;
624
625
2
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
626
2
    if (!fastargs) {
627
0
        goto exit;
628
0
    }
629
2
    if (!noptargs) {
630
2
        goto skip_optional_pos;
631
2
    }
632
0
    if (fastargs[0]) {
633
0
        long_cnt = fastargs[0];
634
0
        if (!--noptargs) {
635
0
            goto skip_optional_pos;
636
0
        }
637
0
    }
638
0
    long_step = fastargs[1];
639
2
skip_optional_pos:
640
2
    return_value = itertools_count_impl(type, long_cnt, long_step);
641
642
2
exit:
643
2
    return return_value;
644
2
}
645
/*[clinic end generated code: output=392c9706e79f6710 input=a9049054013a1b77]*/