1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(dict_fromkeys__doc__,
6 "fromkeys($type, iterable, value=None, /)\n"
7 "--\n"
8 "\n"
9 "Create a new dictionary with keys from iterable and values set to value.");
10
11 #define DICT_FROMKEYS_METHODDEF \
12 {"fromkeys", (PyCFunction)(void(*)(void))dict_fromkeys, METH_FASTCALL|METH_CLASS, dict_fromkeys__doc__},
13
14 static PyObject *
15 dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value);
16
17 static PyObject *
dict_fromkeys(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs)18 dict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
19 {
20 PyObject *return_value = NULL;
21 PyObject *iterable;
22 PyObject *value = Py_None;
23
24 if (!_PyArg_CheckPositional("fromkeys", nargs, 1, 2)) {
25 goto exit;
26 }
27 iterable = args[0];
28 if (nargs < 2) {
29 goto skip_optional;
30 }
31 value = args[1];
32 skip_optional:
33 return_value = dict_fromkeys_impl(type, iterable, value);
34
35 exit:
36 return return_value;
37 }
38
39 PyDoc_STRVAR(dict___contains____doc__,
40 "__contains__($self, key, /)\n"
41 "--\n"
42 "\n"
43 "True if the dictionary has the specified key, else False.");
44
45 #define DICT___CONTAINS___METHODDEF \
46 {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__},
47
48 PyDoc_STRVAR(dict_get__doc__,
49 "get($self, key, default=None, /)\n"
50 "--\n"
51 "\n"
52 "Return the value for key if key is in the dictionary, else default.");
53
54 #define DICT_GET_METHODDEF \
55 {"get", (PyCFunction)(void(*)(void))dict_get, METH_FASTCALL, dict_get__doc__},
56
57 static PyObject *
58 dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
59
60 static PyObject *
dict_get(PyDictObject * self,PyObject * const * args,Py_ssize_t nargs)61 dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
62 {
63 PyObject *return_value = NULL;
64 PyObject *key;
65 PyObject *default_value = Py_None;
66
67 if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
68 goto exit;
69 }
70 key = args[0];
71 if (nargs < 2) {
72 goto skip_optional;
73 }
74 default_value = args[1];
75 skip_optional:
76 return_value = dict_get_impl(self, key, default_value);
77
78 exit:
79 return return_value;
80 }
81
82 PyDoc_STRVAR(dict_setdefault__doc__,
83 "setdefault($self, key, default=None, /)\n"
84 "--\n"
85 "\n"
86 "Insert key with a value of default if key is not in the dictionary.\n"
87 "\n"
88 "Return the value for key if key is in the dictionary, else default.");
89
90 #define DICT_SETDEFAULT_METHODDEF \
91 {"setdefault", (PyCFunction)(void(*)(void))dict_setdefault, METH_FASTCALL, dict_setdefault__doc__},
92
93 static PyObject *
94 dict_setdefault_impl(PyDictObject *self, PyObject *key,
95 PyObject *default_value);
96
97 static PyObject *
dict_setdefault(PyDictObject * self,PyObject * const * args,Py_ssize_t nargs)98 dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
99 {
100 PyObject *return_value = NULL;
101 PyObject *key;
102 PyObject *default_value = Py_None;
103
104 if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) {
105 goto exit;
106 }
107 key = args[0];
108 if (nargs < 2) {
109 goto skip_optional;
110 }
111 default_value = args[1];
112 skip_optional:
113 return_value = dict_setdefault_impl(self, key, default_value);
114
115 exit:
116 return return_value;
117 }
118
119 PyDoc_STRVAR(dict_pop__doc__,
120 "pop($self, key, default=<unrepresentable>, /)\n"
121 "--\n"
122 "\n"
123 "D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n"
124 "\n"
125 "If the key is not found, return the default if given; otherwise,\n"
126 "raise a KeyError.");
127
128 #define DICT_POP_METHODDEF \
129 {"pop", (PyCFunction)(void(*)(void))dict_pop, METH_FASTCALL, dict_pop__doc__},
130
131 static PyObject *
132 dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
133
134 static PyObject *
dict_pop(PyDictObject * self,PyObject * const * args,Py_ssize_t nargs)135 dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
136 {
137 PyObject *return_value = NULL;
138 PyObject *key;
139 PyObject *default_value = NULL;
140
141 if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) {
142 goto exit;
143 }
144 key = args[0];
145 if (nargs < 2) {
146 goto skip_optional;
147 }
148 default_value = args[1];
149 skip_optional:
150 return_value = dict_pop_impl(self, key, default_value);
151
152 exit:
153 return return_value;
154 }
155
156 PyDoc_STRVAR(dict_popitem__doc__,
157 "popitem($self, /)\n"
158 "--\n"
159 "\n"
160 "Remove and return a (key, value) pair as a 2-tuple.\n"
161 "\n"
162 "Pairs are returned in LIFO (last-in, first-out) order.\n"
163 "Raises KeyError if the dict is empty.");
164
165 #define DICT_POPITEM_METHODDEF \
166 {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, dict_popitem__doc__},
167
168 static PyObject *
169 dict_popitem_impl(PyDictObject *self);
170
171 static PyObject *
dict_popitem(PyDictObject * self,PyObject * Py_UNUSED (ignored))172 dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored))
173 {
174 return dict_popitem_impl(self);
175 }
176
177 PyDoc_STRVAR(dict___reversed____doc__,
178 "__reversed__($self, /)\n"
179 "--\n"
180 "\n"
181 "Return a reverse iterator over the dict keys.");
182
183 #define DICT___REVERSED___METHODDEF \
184 {"__reversed__", (PyCFunction)dict___reversed__, METH_NOARGS, dict___reversed____doc__},
185
186 static PyObject *
187 dict___reversed___impl(PyDictObject *self);
188
189 static PyObject *
dict___reversed__(PyDictObject * self,PyObject * Py_UNUSED (ignored))190 dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
191 {
192 return dict___reversed___impl(self);
193 }
194 /*[clinic end generated code: output=7b77c16e43d6735a input=a9049054013a1b77]*/
195