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 key is not found, default is returned if given, otherwise KeyError is raised");
126 
127 #define DICT_POP_METHODDEF    \
128     {"pop", (PyCFunction)(void(*)(void))dict_pop, METH_FASTCALL, dict_pop__doc__},
129 
130 static PyObject *
131 dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
132 
133 static PyObject *
dict_pop(PyDictObject * self,PyObject * const * args,Py_ssize_t nargs)134 dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
135 {
136     PyObject *return_value = NULL;
137     PyObject *key;
138     PyObject *default_value = NULL;
139 
140     if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) {
141         goto exit;
142     }
143     key = args[0];
144     if (nargs < 2) {
145         goto skip_optional;
146     }
147     default_value = args[1];
148 skip_optional:
149     return_value = dict_pop_impl(self, key, default_value);
150 
151 exit:
152     return return_value;
153 }
154 
155 PyDoc_STRVAR(dict_popitem__doc__,
156 "popitem($self, /)\n"
157 "--\n"
158 "\n"
159 "Remove and return a (key, value) pair as a 2-tuple.\n"
160 "\n"
161 "Pairs are returned in LIFO (last-in, first-out) order.\n"
162 "Raises KeyError if the dict is empty.");
163 
164 #define DICT_POPITEM_METHODDEF    \
165     {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, dict_popitem__doc__},
166 
167 static PyObject *
168 dict_popitem_impl(PyDictObject *self);
169 
170 static PyObject *
dict_popitem(PyDictObject * self,PyObject * Py_UNUSED (ignored))171 dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored))
172 {
173     return dict_popitem_impl(self);
174 }
175 
176 PyDoc_STRVAR(dict___reversed____doc__,
177 "__reversed__($self, /)\n"
178 "--\n"
179 "\n"
180 "Return a reverse iterator over the dict keys.");
181 
182 #define DICT___REVERSED___METHODDEF    \
183     {"__reversed__", (PyCFunction)dict___reversed__, METH_NOARGS, dict___reversed____doc__},
184 
185 static PyObject *
186 dict___reversed___impl(PyDictObject *self);
187 
188 static PyObject *
dict___reversed__(PyDictObject * self,PyObject * Py_UNUSED (ignored))189 dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
190 {
191     return dict___reversed___impl(self);
192 }
193 /*[clinic end generated code: output=4d98145508da8fa3 input=a9049054013a1b77]*/
194