Debian Codegraph @

Objects/clinic/enumobject.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
10
11 PyDoc_STRVAR(enum_new__doc__,
12 "enumerate(iterable, start=0)\n"
13 "--\n"
14 "\n"
15 "Return an enumerate object.\n"
16 "\n"
17 " iterable\n"
18 " an object supporting iteration\n"
19 "\n"
20 "The enumerate object yields pairs containing a count (from start, which\n"
21 "defaults to zero) and a value yielded by the iterable argument.\n"
22 "\n"
23 "enumerate is useful for obtaining an indexed list:\n"
24 " (0, seq[0]), (1, seq[1]), (2, seq[2]), ...");
25
26 static PyObject *
27 enum_new_impl(PyTypeObject *type, PyObject *iterable, PyObject *start);
28
29 static PyObject *
30 enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
31 {
32 PyObject *return_value = NULL;
33 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
34
35 #define NUM_KEYWORDS 2
36 static struct {
37 PyGC_Head _this_is_not_used;
38 PyObject_VAR_HEAD
39 Py_hash_t ob_hash;
40 PyObject *ob_item[NUM_KEYWORDS];
41 } _kwtuple = {
42 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
43 .ob_hash = -1,
44 .ob_item = { &_Py_ID(iterable), &_Py_ID(start), },
45 };
46 #undef NUM_KEYWORDS
47 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
48
49 #else // !Py_BUILD_CORE
50 # define KWTUPLE NULL
51 #endif // !Py_BUILD_CORE
52
53 static const char * const _keywords[] = {"iterable", "start", NULL};
54 static _PyArg_Parser _parser = {
55 .keywords = _keywords,
56 .fname = "enumerate",
57 .kwtuple = KWTUPLE,
58 };
59 #undef KWTUPLE
60 PyObject *argsbuf[2];
61 PyObject * const *fastargs;
62 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
63 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
64 PyObject *iterable;
65 PyObject *start = 0;
66
67 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
68 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
69 if (!fastargs) {
70 goto exit;
71 }
72 iterable = fastargs[0];
73 if (!noptargs) {
74 goto skip_optional_pos;
75 }
76 start = fastargs[1];
77 skip_optional_pos:
78 return_value = enum_new_impl(type, iterable, start);
79
80 exit:
81 return return_value;
82 }
83
84 PyDoc_STRVAR(reversed_new__doc__,
85 "reversed(sequence, /)\n"
86 "--\n"
87 "\n"
88 "Return a reverse iterator over the values of the given sequence.");
89
90 static PyObject *
91 reversed_new_impl(PyTypeObject *type, PyObject *seq);
92
93 static PyObject *
94 reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
95 {
96 PyObject *return_value = NULL;
97 PyTypeObject *base_tp = &PyReversed_Type;
98 PyObject *seq;
99
100 if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
101 !_PyArg_NoKeywords("reversed", kwargs)) {
102 goto exit;
103 }
104 if (!_PyArg_CheckPositional("reversed", PyTuple_GET_SIZE(args), 1, 1)) {
105 goto exit;
106 }
107 seq = PyTuple_GET_ITEM(args, 0);
108 return_value = reversed_new_impl(type, seq);
109
110 exit:
111 return return_value;
112 }
113 /*[clinic end generated code: output=3300305b351674d3 input=a9049054013a1b77]*/