/src/Python-3.8.3/Objects/clinic/enumobject.c.h
Line | Count | Source (jump to first uncovered line) |
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 | | enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
25 | 5 | { |
26 | 5 | PyObject *return_value = NULL; |
27 | 5 | static const char * const _keywords[] = {"iterable", "start", NULL}; |
28 | 5 | static _PyArg_Parser _parser = {NULL, _keywords, "enumerate", 0}; |
29 | 5 | PyObject *argsbuf[2]; |
30 | 5 | PyObject * const *fastargs; |
31 | 5 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
32 | 5 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; |
33 | 5 | PyObject *iterable; |
34 | 5 | PyObject *start = 0; |
35 | | |
36 | 5 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf); |
37 | 5 | if (!fastargs) { |
38 | 0 | goto exit; |
39 | 0 | } |
40 | 5 | iterable = fastargs[0]; |
41 | 5 | if (!noptargs) { |
42 | 5 | goto skip_optional_pos; |
43 | 5 | } |
44 | 0 | start = fastargs[1]; |
45 | 5 | skip_optional_pos: |
46 | 5 | return_value = enum_new_impl(type, iterable, start); |
47 | | |
48 | 5 | exit: |
49 | 5 | return return_value; |
50 | 5 | } |
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 | | reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
63 | 16 | { |
64 | 16 | PyObject *return_value = NULL; |
65 | 16 | PyObject *seq; |
66 | | |
67 | 16 | if ((type == &PyReversed_Type) && |
68 | 16 | !_PyArg_NoKeywords("reversed", kwargs)) { |
69 | 0 | goto exit; |
70 | 0 | } |
71 | 16 | if (!_PyArg_CheckPositional("reversed", PyTuple_GET_SIZE(args), 1, 1)) { |
72 | 0 | goto exit; |
73 | 0 | } |
74 | 16 | seq = PyTuple_GET_ITEM(args, 0); |
75 | 16 | return_value = reversed_new_impl(type, seq); |
76 | | |
77 | 16 | exit: |
78 | 16 | return return_value; |
79 | 16 | } |
80 | | /*[clinic end generated code: output=e18c3fefcf914ec7 input=a9049054013a1b77]*/ |