Line data Source code
1 : /*[clinic input]
2 : preserve
3 : [clinic start generated code]*/
4 :
5 : PyDoc_STRVAR(enum_new__doc__,
6 : "enumerate(iterable, start=0)\n"
7 : "--\n"
8 : "\n"
9 : "Return an enumerate object.\n"
10 : "\n"
11 : " iterable\n"
12 : " an object supporting iteration\n"
13 : "\n"
14 : "The enumerate object yields pairs containing a count (from start, which\n"
15 : "defaults to zero) and a value yielded by the iterable argument.\n"
16 : "\n"
17 : "enumerate is useful for obtaining an indexed list:\n"
18 : " (0, seq[0]), (1, seq[1]), (2, seq[2]), ...");
19 :
20 : static PyObject *
21 : enum_new_impl(PyTypeObject *type, PyObject *iterable, PyObject *start);
22 :
23 : static PyObject *
24 44 : enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
25 : {
26 44 : PyObject *return_value = NULL;
27 : static const char * const _keywords[] = {"iterable", "start", NULL};
28 : static _PyArg_Parser _parser = {NULL, _keywords, "enumerate", 0};
29 : PyObject *argsbuf[2];
30 : PyObject * const *fastargs;
31 44 : Py_ssize_t nargs = PyTuple_GET_SIZE(args);
32 44 : Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
33 : PyObject *iterable;
34 44 : PyObject *start = 0;
35 :
36 44 : fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
37 44 : if (!fastargs) {
38 6 : goto exit;
39 : }
40 38 : iterable = fastargs[0];
41 38 : if (!noptargs) {
42 16 : goto skip_optional_pos;
43 : }
44 22 : start = fastargs[1];
45 38 : skip_optional_pos:
46 38 : return_value = enum_new_impl(type, iterable, start);
47 :
48 44 : exit:
49 44 : return return_value;
50 : }
51 :
52 : PyDoc_STRVAR(reversed_new__doc__,
53 : "reversed(sequence, /)\n"
54 : "--\n"
55 : "\n"
56 : "Return a reverse iterator over the values of the given sequence.");
57 :
58 : static PyObject *
59 : reversed_new_impl(PyTypeObject *type, PyObject *seq);
60 :
61 : static PyObject *
62 0 : reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
63 : {
64 0 : PyObject *return_value = NULL;
65 : PyObject *seq;
66 :
67 0 : if ((type == &PyReversed_Type ||
68 0 : type->tp_init == PyReversed_Type.tp_init) &&
69 0 : !_PyArg_NoKeywords("reversed", kwargs)) {
70 0 : goto exit;
71 : }
72 0 : if (!_PyArg_CheckPositional("reversed", PyTuple_GET_SIZE(args), 1, 1)) {
73 0 : goto exit;
74 : }
75 0 : seq = PyTuple_GET_ITEM(args, 0);
76 0 : return_value = reversed_new_impl(type, seq);
77 :
78 0 : exit:
79 0 : return return_value;
80 : }
81 : /*[clinic end generated code: output=a3937b6b33499560 input=a9049054013a1b77]*/
|