LCOV - code coverage report
Current view: top level - Modules/clinic - itertoolsmodule.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 251 264 95.1 %
Date: 2022-07-07 18:19:46 Functions: 17 17 100.0 %

          Line data    Source code
       1             : /*[clinic input]
       2             : preserve
       3             : [clinic start generated code]*/
       4             : 
       5             : PyDoc_STRVAR(pairwise_new__doc__,
       6             : "pairwise(iterable, /)\n"
       7             : "--\n"
       8             : "\n"
       9             : "Return an iterator of overlapping pairs taken from the input iterator.\n"
      10             : "\n"
      11             : "    s -> (s0,s1), (s1,s2), (s2, s3), ...");
      12             : 
      13             : static PyObject *
      14             : pairwise_new_impl(PyTypeObject *type, PyObject *iterable);
      15             : 
      16             : static PyObject *
      17          55 : pairwise_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
      18             : {
      19          55 :     PyObject *return_value = NULL;
      20             :     PyObject *iterable;
      21             : 
      22          55 :     if ((type == &pairwise_type ||
      23          55 :          type->tp_init == pairwise_type.tp_init) &&
      24          11 :         !_PyArg_NoKeywords("pairwise", kwargs)) {
      25           1 :         goto exit;
      26             :     }
      27          54 :     if (!_PyArg_CheckPositional("pairwise", PyTuple_GET_SIZE(args), 1, 1)) {
      28           2 :         goto exit;
      29             :     }
      30          52 :     iterable = PyTuple_GET_ITEM(args, 0);
      31          52 :     return_value = pairwise_new_impl(type, iterable);
      32             : 
      33          55 : exit:
      34          55 :     return return_value;
      35             : }
      36             : 
      37             : PyDoc_STRVAR(itertools_groupby__doc__,
      38             : "groupby(iterable, key=None)\n"
      39             : "--\n"
      40             : "\n"
      41             : "make an iterator that returns consecutive keys and groups from the iterable\n"
      42             : "\n"
      43             : "  iterable\n"
      44             : "    Elements to divide into groups according to the key function.\n"
      45             : "  key\n"
      46             : "    A function for computing the group category for each element.\n"
      47             : "    If the key function is not specified or is None, the element itself\n"
      48             : "    is used for grouping.");
      49             : 
      50             : static PyObject *
      51             : itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc);
      52             : 
      53             : static PyObject *
      54        3254 : itertools_groupby(PyTypeObject *type, PyObject *args, PyObject *kwargs)
      55             : {
      56        3254 :     PyObject *return_value = NULL;
      57             :     static const char * const _keywords[] = {"iterable", "key", NULL};
      58             :     static _PyArg_Parser _parser = {NULL, _keywords, "groupby", 0};
      59             :     PyObject *argsbuf[2];
      60             :     PyObject * const *fastargs;
      61        3254 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
      62        3254 :     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
      63             :     PyObject *it;
      64        3254 :     PyObject *keyfunc = Py_None;
      65             : 
      66        3254 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
      67        3254 :     if (!fastargs) {
      68           1 :         goto exit;
      69             :     }
      70        3253 :     it = fastargs[0];
      71        3253 :     if (!noptargs) {
      72        2408 :         goto skip_optional_pos;
      73             :     }
      74         845 :     keyfunc = fastargs[1];
      75        3253 : skip_optional_pos:
      76        3253 :     return_value = itertools_groupby_impl(type, it, keyfunc);
      77             : 
      78        3254 : exit:
      79        3254 :     return return_value;
      80             : }
      81             : 
      82             : static PyObject *
      83             : itertools__grouper_impl(PyTypeObject *type, PyObject *parent,
      84             :                         PyObject *tgtkey);
      85             : 
      86             : static PyObject *
      87          24 : itertools__grouper(PyTypeObject *type, PyObject *args, PyObject *kwargs)
      88             : {
      89          24 :     PyObject *return_value = NULL;
      90             :     PyObject *parent;
      91             :     PyObject *tgtkey;
      92             : 
      93          24 :     if ((type == &_grouper_type ||
      94          24 :          type->tp_init == _grouper_type.tp_init) &&
      95           0 :         !_PyArg_NoKeywords("_grouper", kwargs)) {
      96           0 :         goto exit;
      97             :     }
      98          24 :     if (!_PyArg_CheckPositional("_grouper", PyTuple_GET_SIZE(args), 2, 2)) {
      99           0 :         goto exit;
     100             :     }
     101          24 :     if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), &groupby_type)) {
     102           0 :         _PyArg_BadArgument("_grouper", "argument 1", (&groupby_type)->tp_name, PyTuple_GET_ITEM(args, 0));
     103           0 :         goto exit;
     104             :     }
     105          24 :     parent = PyTuple_GET_ITEM(args, 0);
     106          24 :     tgtkey = PyTuple_GET_ITEM(args, 1);
     107          24 :     return_value = itertools__grouper_impl(type, parent, tgtkey);
     108             : 
     109          24 : exit:
     110          24 :     return return_value;
     111             : }
     112             : 
     113             : PyDoc_STRVAR(itertools_teedataobject__doc__,
     114             : "teedataobject(iterable, values, next, /)\n"
     115             : "--\n"
     116             : "\n"
     117             : "Data container common to multiple tee objects.");
     118             : 
     119             : static PyObject *
     120             : itertools_teedataobject_impl(PyTypeObject *type, PyObject *it,
     121             :                              PyObject *values, PyObject *next);
     122             : 
     123             : static PyObject *
     124          62 : itertools_teedataobject(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     125             : {
     126          62 :     PyObject *return_value = NULL;
     127             :     PyObject *it;
     128             :     PyObject *values;
     129             :     PyObject *next;
     130             : 
     131          62 :     if ((type == &teedataobject_type ||
     132          62 :          type->tp_init == teedataobject_type.tp_init) &&
     133           0 :         !_PyArg_NoKeywords("teedataobject", kwargs)) {
     134           0 :         goto exit;
     135             :     }
     136          62 :     if (!_PyArg_CheckPositional("teedataobject", PyTuple_GET_SIZE(args), 3, 3)) {
     137           0 :         goto exit;
     138             :     }
     139          62 :     it = PyTuple_GET_ITEM(args, 0);
     140          62 :     if (!PyList_Check(PyTuple_GET_ITEM(args, 1))) {
     141           0 :         _PyArg_BadArgument("teedataobject", "argument 2", "list", PyTuple_GET_ITEM(args, 1));
     142           0 :         goto exit;
     143             :     }
     144          62 :     values = PyTuple_GET_ITEM(args, 1);
     145          62 :     next = PyTuple_GET_ITEM(args, 2);
     146          62 :     return_value = itertools_teedataobject_impl(type, it, values, next);
     147             : 
     148          62 : exit:
     149          62 :     return return_value;
     150             : }
     151             : 
     152             : PyDoc_STRVAR(itertools__tee__doc__,
     153             : "_tee(iterable, /)\n"
     154             : "--\n"
     155             : "\n"
     156             : "Iterator wrapped to make it copyable.");
     157             : 
     158             : static PyObject *
     159             : itertools__tee_impl(PyTypeObject *type, PyObject *iterable);
     160             : 
     161             : static PyObject *
     162          84 : itertools__tee(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     163             : {
     164          84 :     PyObject *return_value = NULL;
     165             :     PyObject *iterable;
     166             : 
     167          84 :     if ((type == &tee_type ||
     168          84 :          type->tp_init == tee_type.tp_init) &&
     169           2 :         !_PyArg_NoKeywords("_tee", kwargs)) {
     170           0 :         goto exit;
     171             :     }
     172          84 :     if (!_PyArg_CheckPositional("_tee", PyTuple_GET_SIZE(args), 1, 1)) {
     173           1 :         goto exit;
     174             :     }
     175          83 :     iterable = PyTuple_GET_ITEM(args, 0);
     176          83 :     return_value = itertools__tee_impl(type, iterable);
     177             : 
     178          84 : exit:
     179          84 :     return return_value;
     180             : }
     181             : 
     182             : PyDoc_STRVAR(itertools_tee__doc__,
     183             : "tee($module, iterable, n=2, /)\n"
     184             : "--\n"
     185             : "\n"
     186             : "Returns a tuple of n independent iterators.");
     187             : 
     188             : #define ITERTOOLS_TEE_METHODDEF    \
     189             :     {"tee", _PyCFunction_CAST(itertools_tee), METH_FASTCALL, itertools_tee__doc__},
     190             : 
     191             : static PyObject *
     192             : itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n);
     193             : 
     194             : static PyObject *
     195         124 : itertools_tee(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     196             : {
     197         124 :     PyObject *return_value = NULL;
     198             :     PyObject *iterable;
     199         124 :     Py_ssize_t n = 2;
     200             : 
     201         124 :     if (!_PyArg_CheckPositional("tee", nargs, 1, 2)) {
     202           2 :         goto exit;
     203             :     }
     204         122 :     iterable = args[0];
     205         122 :     if (nargs < 2) {
     206         111 :         goto skip_optional;
     207             :     }
     208             :     {
     209          11 :         Py_ssize_t ival = -1;
     210          11 :         PyObject *iobj = _PyNumber_Index(args[1]);
     211          11 :         if (iobj != NULL) {
     212           9 :             ival = PyLong_AsSsize_t(iobj);
     213           9 :             Py_DECREF(iobj);
     214             :         }
     215          11 :         if (ival == -1 && PyErr_Occurred()) {
     216           2 :             goto exit;
     217             :         }
     218           9 :         n = ival;
     219             :     }
     220         120 : skip_optional:
     221         120 :     return_value = itertools_tee_impl(module, iterable, n);
     222             : 
     223         124 : exit:
     224         124 :     return return_value;
     225             : }
     226             : 
     227             : PyDoc_STRVAR(itertools_cycle__doc__,
     228             : "cycle(iterable, /)\n"
     229             : "--\n"
     230             : "\n"
     231             : "Return elements from the iterable until it is exhausted. Then repeat the sequence indefinitely.");
     232             : 
     233             : static PyObject *
     234             : itertools_cycle_impl(PyTypeObject *type, PyObject *iterable);
     235             : 
     236             : static PyObject *
     237         218 : itertools_cycle(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     238             : {
     239         218 :     PyObject *return_value = NULL;
     240             :     PyObject *iterable;
     241             : 
     242         218 :     if ((type == &cycle_type ||
     243         218 :          type->tp_init == cycle_type.tp_init) &&
     244          13 :         !_PyArg_NoKeywords("cycle", kwargs)) {
     245           1 :         goto exit;
     246             :     }
     247         217 :     if (!_PyArg_CheckPositional("cycle", PyTuple_GET_SIZE(args), 1, 1)) {
     248           1 :         goto exit;
     249             :     }
     250         216 :     iterable = PyTuple_GET_ITEM(args, 0);
     251         216 :     return_value = itertools_cycle_impl(type, iterable);
     252             : 
     253         218 : exit:
     254         218 :     return return_value;
     255             : }
     256             : 
     257             : PyDoc_STRVAR(itertools_dropwhile__doc__,
     258             : "dropwhile(predicate, iterable, /)\n"
     259             : "--\n"
     260             : "\n"
     261             : "Drop items from the iterable while predicate(item) is true.\n"
     262             : "\n"
     263             : "Afterwards, return every element until the iterable is exhausted.");
     264             : 
     265             : static PyObject *
     266             : itertools_dropwhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
     267             : 
     268             : static PyObject *
     269         440 : itertools_dropwhile(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     270             : {
     271         440 :     PyObject *return_value = NULL;
     272             :     PyObject *func;
     273             :     PyObject *seq;
     274             : 
     275         440 :     if ((type == &dropwhile_type ||
     276         440 :          type->tp_init == dropwhile_type.tp_init) &&
     277          14 :         !_PyArg_NoKeywords("dropwhile", kwargs)) {
     278           1 :         goto exit;
     279             :     }
     280         439 :     if (!_PyArg_CheckPositional("dropwhile", PyTuple_GET_SIZE(args), 2, 2)) {
     281           3 :         goto exit;
     282             :     }
     283         436 :     func = PyTuple_GET_ITEM(args, 0);
     284         436 :     seq = PyTuple_GET_ITEM(args, 1);
     285         436 :     return_value = itertools_dropwhile_impl(type, func, seq);
     286             : 
     287         440 : exit:
     288         440 :     return return_value;
     289             : }
     290             : 
     291             : PyDoc_STRVAR(itertools_takewhile__doc__,
     292             : "takewhile(predicate, iterable, /)\n"
     293             : "--\n"
     294             : "\n"
     295             : "Return successive entries from an iterable as long as the predicate evaluates to true for each entry.");
     296             : 
     297             : static PyObject *
     298             : itertools_takewhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
     299             : 
     300             : static PyObject *
     301          90 : itertools_takewhile(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     302             : {
     303          90 :     PyObject *return_value = NULL;
     304             :     PyObject *func;
     305             :     PyObject *seq;
     306             : 
     307          90 :     if ((type == &takewhile_type ||
     308          90 :          type->tp_init == takewhile_type.tp_init) &&
     309          14 :         !_PyArg_NoKeywords("takewhile", kwargs)) {
     310           1 :         goto exit;
     311             :     }
     312          89 :     if (!_PyArg_CheckPositional("takewhile", PyTuple_GET_SIZE(args), 2, 2)) {
     313           3 :         goto exit;
     314             :     }
     315          86 :     func = PyTuple_GET_ITEM(args, 0);
     316          86 :     seq = PyTuple_GET_ITEM(args, 1);
     317          86 :     return_value = itertools_takewhile_impl(type, func, seq);
     318             : 
     319          90 : exit:
     320          90 :     return return_value;
     321             : }
     322             : 
     323             : PyDoc_STRVAR(itertools_starmap__doc__,
     324             : "starmap(function, iterable, /)\n"
     325             : "--\n"
     326             : "\n"
     327             : "Return an iterator whose values are returned from the function evaluated with an argument tuple taken from the given sequence.");
     328             : 
     329             : static PyObject *
     330             : itertools_starmap_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
     331             : 
     332             : static PyObject *
     333        9031 : itertools_starmap(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     334             : {
     335        9031 :     PyObject *return_value = NULL;
     336             :     PyObject *func;
     337             :     PyObject *seq;
     338             : 
     339        9031 :     if ((type == &starmap_type ||
     340        9031 :          type->tp_init == starmap_type.tp_init) &&
     341          13 :         !_PyArg_NoKeywords("starmap", kwargs)) {
     342           1 :         goto exit;
     343             :     }
     344        9030 :     if (!_PyArg_CheckPositional("starmap", PyTuple_GET_SIZE(args), 2, 2)) {
     345           2 :         goto exit;
     346             :     }
     347        9028 :     func = PyTuple_GET_ITEM(args, 0);
     348        9028 :     seq = PyTuple_GET_ITEM(args, 1);
     349        9028 :     return_value = itertools_starmap_impl(type, func, seq);
     350             : 
     351        9031 : exit:
     352        9031 :     return return_value;
     353             : }
     354             : 
     355             : PyDoc_STRVAR(itertools_chain_from_iterable__doc__,
     356             : "from_iterable($type, iterable, /)\n"
     357             : "--\n"
     358             : "\n"
     359             : "Alternative chain() constructor taking a single iterable argument that evaluates lazily.");
     360             : 
     361             : #define ITERTOOLS_CHAIN_FROM_ITERABLE_METHODDEF    \
     362             :     {"from_iterable", (PyCFunction)itertools_chain_from_iterable, METH_O|METH_CLASS, itertools_chain_from_iterable__doc__},
     363             : 
     364             : PyDoc_STRVAR(itertools_combinations__doc__,
     365             : "combinations(iterable, r)\n"
     366             : "--\n"
     367             : "\n"
     368             : "Return successive r-length combinations of elements in the iterable.\n"
     369             : "\n"
     370             : "combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)");
     371             : 
     372             : static PyObject *
     373             : itertools_combinations_impl(PyTypeObject *type, PyObject *iterable,
     374             :                             Py_ssize_t r);
     375             : 
     376             : static PyObject *
     377        6015 : itertools_combinations(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     378             : {
     379        6015 :     PyObject *return_value = NULL;
     380             :     static const char * const _keywords[] = {"iterable", "r", NULL};
     381             :     static _PyArg_Parser _parser = {NULL, _keywords, "combinations", 0};
     382             :     PyObject *argsbuf[2];
     383             :     PyObject * const *fastargs;
     384        6015 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     385             :     PyObject *iterable;
     386             :     Py_ssize_t r;
     387             : 
     388        6015 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
     389        6015 :     if (!fastargs) {
     390           3 :         goto exit;
     391             :     }
     392        6012 :     iterable = fastargs[0];
     393             :     {
     394        6012 :         Py_ssize_t ival = -1;
     395        6012 :         PyObject *iobj = _PyNumber_Index(fastargs[1]);
     396        6012 :         if (iobj != NULL) {
     397        6012 :             ival = PyLong_AsSsize_t(iobj);
     398        6012 :             Py_DECREF(iobj);
     399             :         }
     400        6012 :         if (ival == -1 && PyErr_Occurred()) {
     401           0 :             goto exit;
     402             :         }
     403        6012 :         r = ival;
     404             :     }
     405        6012 :     return_value = itertools_combinations_impl(type, iterable, r);
     406             : 
     407        6015 : exit:
     408        6015 :     return return_value;
     409             : }
     410             : 
     411             : PyDoc_STRVAR(itertools_combinations_with_replacement__doc__,
     412             : "combinations_with_replacement(iterable, r)\n"
     413             : "--\n"
     414             : "\n"
     415             : "Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats.\n"
     416             : "\n"
     417             : "combinations_with_replacement(\'ABC\', 2) --> (\'A\',\'A\'), (\'A\',\'B\'), (\'A\',\'C\'), (\'B\',\'B\'), (\'B\',\'C\'), (\'C\',\'C\')");
     418             : 
     419             : static PyObject *
     420             : itertools_combinations_with_replacement_impl(PyTypeObject *type,
     421             :                                              PyObject *iterable,
     422             :                                              Py_ssize_t r);
     423             : 
     424             : static PyObject *
     425        1001 : itertools_combinations_with_replacement(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     426             : {
     427        1001 :     PyObject *return_value = NULL;
     428             :     static const char * const _keywords[] = {"iterable", "r", NULL};
     429             :     static _PyArg_Parser _parser = {NULL, _keywords, "combinations_with_replacement", 0};
     430             :     PyObject *argsbuf[2];
     431             :     PyObject * const *fastargs;
     432        1001 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     433             :     PyObject *iterable;
     434             :     Py_ssize_t r;
     435             : 
     436        1001 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
     437        1001 :     if (!fastargs) {
     438           3 :         goto exit;
     439             :     }
     440         998 :     iterable = fastargs[0];
     441             :     {
     442         998 :         Py_ssize_t ival = -1;
     443         998 :         PyObject *iobj = _PyNumber_Index(fastargs[1]);
     444         998 :         if (iobj != NULL) {
     445         998 :             ival = PyLong_AsSsize_t(iobj);
     446         998 :             Py_DECREF(iobj);
     447             :         }
     448         998 :         if (ival == -1 && PyErr_Occurred()) {
     449           0 :             goto exit;
     450             :         }
     451         998 :         r = ival;
     452             :     }
     453         998 :     return_value = itertools_combinations_with_replacement_impl(type, iterable, r);
     454             : 
     455        1001 : exit:
     456        1001 :     return return_value;
     457             : }
     458             : 
     459             : PyDoc_STRVAR(itertools_permutations__doc__,
     460             : "permutations(iterable, r=None)\n"
     461             : "--\n"
     462             : "\n"
     463             : "Return successive r-length permutations of elements in the iterable.\n"
     464             : "\n"
     465             : "permutations(range(3), 2) --> (0,1), (0,2), (1,0), (1,2), (2,0), (2,1)");
     466             : 
     467             : static PyObject *
     468             : itertools_permutations_impl(PyTypeObject *type, PyObject *iterable,
     469             :                             PyObject *robj);
     470             : 
     471             : static PyObject *
     472       28305 : itertools_permutations(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     473             : {
     474       28305 :     PyObject *return_value = NULL;
     475             :     static const char * const _keywords[] = {"iterable", "r", NULL};
     476             :     static _PyArg_Parser _parser = {NULL, _keywords, "permutations", 0};
     477             :     PyObject *argsbuf[2];
     478             :     PyObject * const *fastargs;
     479       28305 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     480       28305 :     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
     481             :     PyObject *iterable;
     482       28305 :     PyObject *robj = Py_None;
     483             : 
     484       28305 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
     485       28305 :     if (!fastargs) {
     486           2 :         goto exit;
     487             :     }
     488       28303 :     iterable = fastargs[0];
     489       28303 :     if (!noptargs) {
     490       27323 :         goto skip_optional_pos;
     491             :     }
     492         980 :     robj = fastargs[1];
     493       28303 : skip_optional_pos:
     494       28303 :     return_value = itertools_permutations_impl(type, iterable, robj);
     495             : 
     496       28305 : exit:
     497       28305 :     return return_value;
     498             : }
     499             : 
     500             : PyDoc_STRVAR(itertools_accumulate__doc__,
     501             : "accumulate(iterable, func=None, *, initial=None)\n"
     502             : "--\n"
     503             : "\n"
     504             : "Return series of accumulated sums (or other binary function results).");
     505             : 
     506             : static PyObject *
     507             : itertools_accumulate_impl(PyTypeObject *type, PyObject *iterable,
     508             :                           PyObject *binop, PyObject *initial);
     509             : 
     510             : static PyObject *
     511         185 : itertools_accumulate(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     512             : {
     513         185 :     PyObject *return_value = NULL;
     514             :     static const char * const _keywords[] = {"iterable", "func", "initial", NULL};
     515             :     static _PyArg_Parser _parser = {NULL, _keywords, "accumulate", 0};
     516             :     PyObject *argsbuf[3];
     517             :     PyObject * const *fastargs;
     518         185 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     519         185 :     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
     520             :     PyObject *iterable;
     521         185 :     PyObject *binop = Py_None;
     522         185 :     PyObject *initial = Py_None;
     523             : 
     524         185 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
     525         185 :     if (!fastargs) {
     526           3 :         goto exit;
     527             :     }
     528         182 :     iterable = fastargs[0];
     529         182 :     if (!noptargs) {
     530         102 :         goto skip_optional_pos;
     531             :     }
     532          80 :     if (fastargs[1]) {
     533          71 :         binop = fastargs[1];
     534          71 :         if (!--noptargs) {
     535          71 :             goto skip_optional_pos;
     536             :         }
     537             :     }
     538           9 : skip_optional_pos:
     539         182 :     if (!noptargs) {
     540         173 :         goto skip_optional_kwonly;
     541             :     }
     542           9 :     initial = fastargs[2];
     543         182 : skip_optional_kwonly:
     544         182 :     return_value = itertools_accumulate_impl(type, iterable, binop, initial);
     545             : 
     546         185 : exit:
     547         185 :     return return_value;
     548             : }
     549             : 
     550             : PyDoc_STRVAR(itertools_compress__doc__,
     551             : "compress(data, selectors)\n"
     552             : "--\n"
     553             : "\n"
     554             : "Return data elements corresponding to true selector elements.\n"
     555             : "\n"
     556             : "Forms a shorter iterator from selected data elements using the selectors to\n"
     557             : "choose the data elements.");
     558             : 
     559             : static PyObject *
     560             : itertools_compress_impl(PyTypeObject *type, PyObject *seq1, PyObject *seq2);
     561             : 
     562             : static PyObject *
     563         293 : itertools_compress(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     564             : {
     565         293 :     PyObject *return_value = NULL;
     566             :     static const char * const _keywords[] = {"data", "selectors", NULL};
     567             :     static _PyArg_Parser _parser = {NULL, _keywords, "compress", 0};
     568             :     PyObject *argsbuf[2];
     569             :     PyObject * const *fastargs;
     570         293 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     571             :     PyObject *seq1;
     572             :     PyObject *seq2;
     573             : 
     574         293 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
     575         293 :     if (!fastargs) {
     576           2 :         goto exit;
     577             :     }
     578         291 :     seq1 = fastargs[0];
     579         291 :     seq2 = fastargs[1];
     580         291 :     return_value = itertools_compress_impl(type, seq1, seq2);
     581             : 
     582         293 : exit:
     583         293 :     return return_value;
     584             : }
     585             : 
     586             : PyDoc_STRVAR(itertools_filterfalse__doc__,
     587             : "filterfalse(function, iterable, /)\n"
     588             : "--\n"
     589             : "\n"
     590             : "Return those items of iterable for which function(item) is false.\n"
     591             : "\n"
     592             : "If function is None, return the items that are false.");
     593             : 
     594             : static PyObject *
     595             : itertools_filterfalse_impl(PyTypeObject *type, PyObject *func, PyObject *seq);
     596             : 
     597             : static PyObject *
     598         407 : itertools_filterfalse(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     599             : {
     600         407 :     PyObject *return_value = NULL;
     601             :     PyObject *func;
     602             :     PyObject *seq;
     603             : 
     604         407 :     if ((type == &filterfalse_type ||
     605         407 :          type->tp_init == filterfalse_type.tp_init) &&
     606          15 :         !_PyArg_NoKeywords("filterfalse", kwargs)) {
     607           1 :         goto exit;
     608             :     }
     609         406 :     if (!_PyArg_CheckPositional("filterfalse", PyTuple_GET_SIZE(args), 2, 2)) {
     610           3 :         goto exit;
     611             :     }
     612         403 :     func = PyTuple_GET_ITEM(args, 0);
     613         403 :     seq = PyTuple_GET_ITEM(args, 1);
     614         403 :     return_value = itertools_filterfalse_impl(type, func, seq);
     615             : 
     616         407 : exit:
     617         407 :     return return_value;
     618             : }
     619             : 
     620             : PyDoc_STRVAR(itertools_count__doc__,
     621             : "count(start=0, step=1)\n"
     622             : "--\n"
     623             : "\n"
     624             : "Return a count object whose .__next__() method returns consecutive values.\n"
     625             : "\n"
     626             : "Equivalent to:\n"
     627             : "    def count(firstval=0, step=1):\n"
     628             : "        x = firstval\n"
     629             : "        while 1:\n"
     630             : "            yield x\n"
     631             : "            x += step");
     632             : 
     633             : static PyObject *
     634             : itertools_count_impl(PyTypeObject *type, PyObject *long_cnt,
     635             :                      PyObject *long_step);
     636             : 
     637             : static PyObject *
     638       17323 : itertools_count(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     639             : {
     640       17323 :     PyObject *return_value = NULL;
     641             :     static const char * const _keywords[] = {"start", "step", NULL};
     642             :     static _PyArg_Parser _parser = {NULL, _keywords, "count", 0};
     643             :     PyObject *argsbuf[2];
     644             :     PyObject * const *fastargs;
     645       17323 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     646       17323 :     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
     647       17323 :     PyObject *long_cnt = NULL;
     648       17323 :     PyObject *long_step = NULL;
     649             : 
     650       17323 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
     651       17323 :     if (!fastargs) {
     652           1 :         goto exit;
     653             :     }
     654       17322 :     if (!noptargs) {
     655        4097 :         goto skip_optional_pos;
     656             :     }
     657       13225 :     if (fastargs[0]) {
     658       13223 :         long_cnt = fastargs[0];
     659       13223 :         if (!--noptargs) {
     660       11487 :             goto skip_optional_pos;
     661             :         }
     662             :     }
     663        1738 :     long_step = fastargs[1];
     664       17322 : skip_optional_pos:
     665       17322 :     return_value = itertools_count_impl(type, long_cnt, long_step);
     666             : 
     667       17323 : exit:
     668       17323 :     return return_value;
     669             : }
     670             : /*[clinic end generated code: output=659251a811ff89ed input=a9049054013a1b77]*/

Generated by: LCOV version 1.14